PowerShell – Passing An Argument List Within A Script Block


$Options = @{'Variable'='test'}

Invoke-Command -ArgumentList $Options -ScriptBlock {
Param($Options)&{
Param(
[string]
$Variable
)
Write-Output -InputObject "ComputerName: $env:COMPUTERNAME"
Write-Output -InputObject "Variable: $Variable"
} @Options
} # End: Script block

# Sample Output:
# ComputerName: MY-LOCALHOST
# Variable: test

Thanks to this post:
http://stackoverflow.com/questions/28234509/powershell-splatting-the-argumentlist-on-invoke-command

Advertisements