powershell - How to execute script block on remote machine that uses local variable as an argument -
i run application passing arguments remote machine. i've got following work on remote machine running locally:
foreach ($a in $args){ &"c:\program files\christiansteven\crd\crd.exe" "-s schedulename=vc_$($a)" }
i'm having problems running remotely using:
foreach ($a in $args){ invoke-command -computername $serv -credential $cred -scriptblock {param($b) &"c:\program files\christiansteven\crd\crd.exe" $b} -argumentlist "-s schedulename=vc_$($a)" }
from i've read variables scope , remedy create scriptblock before pass remote machine using:
[scriptblock]::create(<command>)
i've tried many combinations , can't run.
you can this:
$scriptblock = {param($a) &"c:\program files\christiansteven\crd\crd.exe" "-s schedulename=vc_$($a)"} foreach ($a in $args){ invoke-command -computername $serv -credential $cred -scriptblock $scriptblock -argumentlist $a }
Comments
Post a Comment