Forum Discussion
SunPower
Jul 09, 2021Copper Contributor
Invoke-Command ScriptBlock issue
Hi All, am facing some issues when using invoke commamd.
Issue1: if I say invoke-command -computername abc -scriptblock{c:\abc\runprocess.cmd -create}
This is working fine.
But if I put c:\abc\runprocess.cmd -create in variable abcpath it’s not working as expected.
Command a I tried:
invoke-command -computername abc -scriptblock{$abcpath} this isn’t printing anything.
Command b I tried
invoke-command -computername abc -scriptblock{$args} -ArgumentList this isn’t 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.
Issue1: if I say invoke-command -computername abc -scriptblock{c:\abc\runprocess.cmd -create}
This is working fine.
But if I put c:\abc\runprocess.cmd -create in variable abcpath it’s not working as expected.
Command a I tried:
invoke-command -computername abc -scriptblock{$abcpath} this isn’t printing anything.
Command b I tried
invoke-command -computername abc -scriptblock{$args} -ArgumentList this isn’t 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.
- psophosBrass Contributor
Does calling it like this work?:
$abcPath = { c:\abc\runprocess.cmd -create } invoke-command -computername abc -scriptblock $abcPath
Note the lack of { } after the -scriptblock parameter.