I have syntax similar to the below in PowerShell:
param($1,$2,$3,$4)
$Session = New-PSSession -ComputerName $1
$scriptblock = $ExecutionContext.InvokeCommand.NewScriptBlock("cmd /c $2 $3 $4")
Invoke-Command -Session $Session -ScriptBlock $scriptblock
Where $2 is a .bat and $3 & $4 are arguments I want to pass to the executable. If I run it without arguments I can run the .bat but when I add in the arguments it fails. What am I doing wrong?
I am calling the above by running this in PowerShell:
-ExecutionPolicy Bypass -F "powershellscript for the above" -1 "value" -2 "value" -3 "value" -4 "value"
cmdon the remote machine might not be able to find the batch file on the remote machine - the argument you pass as-2, is it a fully rooted path? Does it have spaces in it? To verify that the local PowerShell bits are working, try replacing theInvoke-Commandstatement withWrite-Host "About to execute { $sriptblock } against $1"