Cannot validate argument on parameter ‘Name’. The argument is null or empty. Provide an argument that is not null or
empty, and then try the command again.
Second Method:
PS > Invoke-Command -Session $s -Scriptblock{ & "C:\Users\Administrator\Desktop\Test.ps1 " -RName $using:Name -RCPU $using:CPU} Cannot validate argument on parameter ‘Name’. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again. + CategoryInfo : InvalidData: ( [Get-Process], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetProcessCommand
I’m lost my crystal ball and can’t help witout seeing your code
but I try…
I Don’t see the -Name parameter in your Test.ps1 call, but I see -RName
there is something wrong inside Test.ps1.
if Test.ps1 have parameter() block ?
How it call Get-Process ? may be just wrong typing
In your second example, I’m not seeing where you first defined $name and $cpu locally. But, you’re also using the invocation operator (&), which I don’t understand. That’s going to prevent $using from working correctly, as it doesn’t occur in the actual -Scriptblock parameter.
@Max Kozlow : You were right, I had commented out the Get-Process part inside test.ps1 but had pasted the output that I used to get when it exist. I’m sorry for the confusion. But I still don’t see the variables being retrieved by the destination PS script. I’m listing out the methods I have tried and couldn’t succeed in either of them.
For all the above three methods I get only the value of the ‘local variable’(local to destination machine and declared there in the script) gets printed and not the variable I pass(here $Name) from my local machine on to the destination machine.
@Max Kozlov: Thanks for making me understand the use of variables even though that didn’t solve the actual issue/problem I had with. I figured out the answer and have explained on how this feature works.
I figured out the way on how this feature works with the help of a Senior Architect here in our company. The variables sent from the local(source machine) are not actually made local on the remote machine and these just get dumped as values on the remote machine and not as variables(you can’t use variables). A simple example on how the above script which I had mentioned works
Now you see that you get the required output on the remote machine, so it conveys that the values are directly getting dumped and not with the variables and hence I was earlier not able to use those variables on the remote machine.