Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Sunday, August 24, 2014 2:00 PM
Hi there,
i am facing a "for me" confusing error in ISE...
I just started with PS Scripting and created the following little script:
Param(
[string]$computerName,
[string]$RegKey
)
Invoke-Command -computername $computerName {Remove-Item -path $RegKey -Recurse}
When running this i am getting that Error:
Cannot bind argument to parameter 'Path' because it is null.
+ CategoryInfo : InvalidData: (:) [Remove-Item], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Co
mmands.RemoveItemCommand
+ PSComputerName : xxxxxxx
Whle Debugging i verified the Parameters, they looked good, if i fire the invoke-command line alone it works fine, so i dont get it whats wrong with that?!?
Any idea hint, help?
best regards
Christof
All replies (2)
Sunday, August 24, 2014 2:15 PM âś…Answered | 1 vote
The problem is that you're creating the variable on your local computer and then expecting the remote computer to somehow know something about your variable. Here's how you can handle this problem.
Invoke-Command -computername $computerName {Remove-Item -path $args[0] -Recurse} -ArgumentList $RegKey
Here's a good read with additional examples: http://blogs.msdn.com/b/powershell/archive/2009/12/29/arguments-for-remote-commands.aspx. Good luck!
Edit: Added URL
Sunday, August 24, 2014 3:05 PM
great, thats it, MS should really work on such second sight features ;)
Thank you for that fast answer!