Solved

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

Posted on 2010-09-20
16
5,181 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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Background Information Recently I have fixed file server permission issues for one of my client. The client has 1800 users and one Windows Server 2008 R2 domain joined file server with 12 TB of data, 250+ shared folders and the folder structure i…
After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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 …

617 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