Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2010-09-20
16
Medium Priority
?
5,370 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
Use Filtering Commands to Process Files in Linux

Learn how to manipulate data with the help of various filtering commands such as `cat`, `fmt`, `pr`, and others in Linux.

 

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 1000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

704 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