Solved

Error while running powershell script - Cannot bind argument to parameter 'Path' because it is null.

Posted on 2010-09-20
16
5,063 Views
Last Modified: 2012-05-10
Hello,

I have one script for renaming homefolders and setting ACLs. It works on my personal laptop but not  at work.
Gives me this error: "Cannot bind argument to parameter 'Path' because it is null.
At :line:5 char:11
+   (Get-Item <<<<  $_.ColumnA).MoveTo($_.ColumnB)"

I know its probably some settings, but I cannot manage it.
I am running PowerGui script editor ver. 2.1.1.1202 .

Any idea?

Many thx

-------------------------------

$DomainName = "xxx"
$LogosDomain = "yyyy"
 
Import-CSV C:\users.csv | %{

  $Folder = Get-Item $_.ColumnA
 
    $NewFullName = $Folder.FullName -Replace $Folder.Name, $_.ColumnB
 
  $Folder.MoveTo($NewFullName)
 
  $ACL = Get-ACL $NewFullName
 
   $AccessRule2 = New-Object Security.AccessControl.FileSystemAccessRule( `
  "$LogosDomain\$($_.ColumnA)", @("Modify", "Synchronize"), @("ObjectInherit", "ContainerInherit"), "InheritOnly", "Allow")
 
 
  $AccessRule = New-Object `
    System.Security.AccessControl.FileSystemAccessRule(`
      "$DomainName\$($_.ColumnB)",@("Modify","Synchronize"), @("ObjectInherit", "ContainerInherit"), "NoPropagateInherit", "Allow")

 
  $ACL.RemoveAccessRuleAll($accessrule2)
  $ACL.AddAccessRule($AccessRule)
 

  Set-ACL $NewFullName -AclObject $ACL
}



0
Comment
Question by:Radim88
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 7
16 Comments
 
LVL 71

Expert Comment

by:Chris Dent
ID: 33723229

It reads like a problem in your input file rather than the script.

I suggest you Write-Host the values it's trying to use before you use them.

Chris
0
 

Author Comment

by:Radim88
ID: 33724018
Hello, csv file looks like this :

ColumnA;ColumnB
C:\A;C
C:\B;D

------------------------

IF I RUN:

Import-CSV C:\test.csv

I GET:

ColumnA;ColumnB                                                                                  
---------------                                                                                  
C:\A;C                                                                                          
C:\B;D      

BUT IT FAILS ON(Get-Item):

Import-CSV C:\test.csv | %{
 
   
  $Folder = Get-Item $_.ColumnA

   $NewFullName = $Folder.FullName -Replace $Folder.Name, $_.ColumnB
 
   $Folder.MoveTo($NewFullName)
   
   write $NewFullName
   }
                                                                                     

Many Thanks


0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 33724025

That's not a CSV file.

CSV is Comma Separated Values, your delimiter is a semi-colon.

You can either change that, or run Import-Csv like this:

Import-Csv C:\test.csv -Delimiter ";" | ....

Chris
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 

Author Comment

by:Radim88
ID: 33724477
Hi,

I dont know.
---------------------------------------------

Import-CSV C:\test.csv -Delimiter ";" | %{

 
  $Folder = Get-Item $_.ColumnA
 
  $Folder
  }

--------------------


Cannot bind argument to parameter 'Path' because it is an empty string.
At :line:7 char:20
+   $Folder = Get-Item <<<<  $_.ColumnA
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 33724531

Run this bit on its own and check you get something useful back:

Import-CSV C:\test.csv -Delimiter ";"

It's entirely possible you have trailing blank lines as well.

Chris
0
 

Author Comment

by:Radim88
ID: 33724576
Import-CSV C:\test.csv -Delimiter ";"

---------------------------------------

ColumnA                                                                 ColumnB                                                                
-------                                                                 -------                                                                
C:\A                                                                    B        
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 33724613

Try this:


Import-Csv "C:\test.csv" -Delimiter ";" | ForEach-Object {
  Write-Host "Path: '$($_.ColumnA)'"
  Get-Item $_.ColumnA
}


See how many times it tells you about Path.

Chris
0
 

Author Comment

by:Radim88
ID: 33724656
Path: ''
Cannot bind argument to parameter 'Path' because it is an empty string.
At :line:3 char:10
+   Get-Item <<<<  $_.ColumnA
0
 

Author Comment

by:Radim88
ID: 33724674
But it makes me crazy, i have at home installed server 2003 in virtual pc, I installed there powergui etc..
And it works.
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 33724677

You have an empty line in your file.

You could work around that in PowerShell, but it's a problem in the file, not PowerShell.

Chris
Import-Csv "C:\test.csv" -Delimiter ";" | Where-Object { $_.ColumnA } | ForEach-Object {
  Write-Host "Path: '$($_.ColumnA)'"
  Get-Item $_.ColumnA
}

Open in new window

0
 

Author Comment

by:Radim88
ID: 33724813
So do y think is there possible solution to remake script or should I use:

ren C:\A B | icacls c:\B /remove xx\yy /grant xx\yy:(OI)(CI)(M)

many thanks

0
 

Author Comment

by:Radim88
ID: 33724857
by the way it gives me:

Path: 'C:\A'
Cannot find path 'C:\A' because it does not exist.
At :line:3 char:10
+   Get-Item <<<<  $_.ColumnA

Path: 'C:\B'
Cannot find path 'C:\B' because it does not exist.
At :line:3 char:10
+   Get-Item <<<<  $_.ColumnA
0
 
LVL 71

Accepted Solution

by:
Chris Dent earned 250 total points
ID: 33724879

I don't see a need to remake the script, there's really not very much to it.

> ren C:\A B | icacls c:\B /remove xx\yy /grant xx\yy:(OI)(CI)(M)

You don't really want a pipeline there, you're not passing anything along. You can just use:

ren C:\A B
icacls c:\B /remove xx\yy /grant xx\yy:(OI)(CI)(M)

And the error message... well if that path doesn't exist... I can't help you with that :)

Chris
0
 

Author Comment

by:Radim88
ID: 33724949
Thanks :-) , I am an idiot. Let me ask you another question before I accept it.

ren C:\A B | icacls c:\B /remove xx\yy /grant xx\yy:(OI)(CI)(M)

I know it doesn't send an object via pipe. I only wanted to pass it into one line, I have about 600 homefolders and wanted to create a *.bat and run it at the same time.

Thanks again
0
 

Author Closing Comment

by:Radim88
ID: 33724981
thx
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 33725035

If it's PowerShell you can pop things on a single line with ;. e.g.

Rename-Item C:\A B; DoOtherStuff

With Batch you can use &&. e.g.

ren C:\ B && icacls ...

Chris
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question