Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dan1el42/bda9907e3bdf29e8940d2c25094f80d2 to your computer and use it in GitHub Desktop.
Save Dan1el42/bda9907e3bdf29e8940d2c25094f80d2 to your computer and use it in GitHub Desktop.
$Servers = @(
'server1.example.com'
'server2.example.com'
'server1000.example.com'
)
$ScriptBlock = {
$x = 10
"start first command with $x"
Start-Sleep -Milliseconds 10000
'ok, im done'
$x = $x - 5
"start second command with $x"
Start-Sleep -Milliseconds 10000
'ok, im done'
"x = $x"
}
$Jobs = Invoke-Command -ComputerName $Servers -ScriptBlock $ScriptBlock -AsJob
$Jobs | Wait-Job
$Jobs | Receive-Job | Format-Table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment