Pass arguments to a scriptblock in powershell -


i guess can't this:

  $servicepath = $args[0]    if(test-path -path $servicepath) <-- not throw in here    $block = {          write-host $servicepath -foreground "magenta"          if((test-path -path $servicepath)) { <-- throws here.                dowork          }   } 

so how can pass variables scriptblock $block?

keith's answer works invoke-command, limit can't use named parameters. arguments should set using -argumentlist parameter , should comma separated.

$sb = {param($p1,$p2) $ofs=','; "p1 $p1, p2 $p2, rest of args: $args"} invoke-command $sb -argumentlist 1,2,3,4 

also see here , here.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -