Forum Discussion
Invoke-Command ScriptBlock issue
Thanks for your reply psophos but issue is not resolved. Still same behavior - basically it's not displaying anything.
I would not expect it to display anything as the code is being executed on the remote computer.
- SunPowerJul 09, 2021Copper Contributor
- psophosJul 09, 2021Brass ContributorHmm. If the .cmd file produces output then I would expect to see it in $result.
- SunPowerJul 09, 2021Copper Contributor
$result = invoke-command -computername abc -scriptblock{c:\abc\runprocess.cmd -create}
$result
am getting expected output with above.
command a I tried.
$abcpath = "c:\abc\runprocess.cmd -create"
$result = invoke-command -computername abc -scriptblock{$abcpath}$result
this isn’t printing anything.
Command b I tried
$abcpath = "c:\abc\runprocess.cmd -create"
$result = invoke-command -computername abc -scriptblock{$args} -ArgumentList $abcpath $resultThis is printing c:\abc\runprocess.cmd -create as is but it’s not executing.
Please advice and any pointers will be helpful.
In summary I want to know how I can use variables in script block and such that command can be executed in machine -computerName I specified.