Solved

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

Posted on 2010-09-20
16
4,685 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
Comment Utility

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
Comment Utility
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
Comment Utility

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
 

Author Comment

by:Radim88
Comment Utility
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
Comment Utility

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
Comment Utility
Import-CSV C:\test.csv -Delimiter ";"

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

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

Expert Comment

by:Chris Dent
Comment Utility

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
Comment Utility
Path: ''
Cannot bind argument to parameter 'Path' because it is an empty string.
At :line:3 char:10
+   Get-Item <<<<  $_.ColumnA
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Radim88
Comment Utility
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
Comment Utility

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
Comment Utility
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
Comment Utility
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
Comment Utility

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
Comment Utility
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
Comment Utility
thx
0
 
LVL 70

Expert Comment

by:Chris Dent
Comment Utility

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

You might have come across a situation when you have Exchange 2013 server in two different sites (Production and DR). After adding the Database copy in ECP console it displays Database copy status unknown for the DR exchange server. Issue is strange…
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
The viewer will learn how to dynamically set the form action using jQuery.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now