Solved

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

Posted on 2010-09-20
16
4,872 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
  • 9
  • 7
16 Comments
 
LVL 70

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 70

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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 70

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 70

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 70

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 70

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 70

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Utilizing an array to gracefully append to a list of EmailAddresses
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

776 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