A N

November 14, 2014

Passing variable to remote machine (Invoke-Command)

Filed under: Tips — donrsh @ 11:38 am

In PowerShell 3.0 we can simply use the Using scope modifier followed by a colon and the name of the local variable we want to reference:

$a = "PowerShell"
$b = "Rocks"
Invoke-Command -ComputerName Server01 -ScriptBlock {
   Write-Output "The value of `$a is: $using:a"
   Write-Output "The value of `$b is: $using:b"
}
 
The value of $a is: PowerShell
The value of $b is: Rocks
Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: