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

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -