I\'m writing a PowerShell script that will execute commands on a remote host using Invoke-Command and its -ScriptBlock parameter. For example,
-ScriptBlock
This also works:
function foo { param([string]$hosts, [string]$commands) $scriptblock = $executioncontext.invokecommand.NewScriptBlock($commands) $hosts.split(",") |% { Invoke-Command -Credential $cred -ComputerName $_.trim() -Scriptblock $scriptblock } }