Powershell Remoting Handover Variables

Posted by icnivad on Server Fault See other posts from Server Fault or by icnivad
Published on 2010-05-03T14:38:27Z Indexed on 2010/05/03 14:48 UTC
Read the original article Hit count: 352

I've opened a Remote Session s1, and like to run a function with Parameters i handover in my scriptblock:

Simplified example with Write-Host:

$a = "aaa"
$b = "bbb"
$c = "ccc"
$d = "ddd"
Write-Host "AAAAA: $a $b $c $d"  #This works fine as it's locally


Invoke-Command -Session $s1 -scriptblock {Write-Host "BBBBB: $a $b $c $d"}  #These variables are empty

What is the cleanest way to handover Variables (I normally receive from a local csv file) to the scriptblock?

© Server Fault or respective owner

Related posts about powershell

Related posts about powershell-v2.0