Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 1 down vote accepted

You need to "pass" the parameters into your script block using the ArgumentList parameter on Invoke-Command. This should do it for you:

Invoke-Command -Session $s1 -scriptblock {param($a, $b, $c, $d) Write-Host "BBBBB: $a $b $c $d"} -ArgumentList $a, $b, $c, $d
share|improve this answer
Thanks, Already played with param but i was missing the -ArgumentList – icnivad May 3 '10 at 16:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.