Created
July 27, 2016 19:02
-
-
Save Dan1el42/bda9907e3bdf29e8940d2c25094f80d2 to your computer and use it in GitHub Desktop.
A posssible solution for https://powershell.org/forums/topic/disconnected-ps-session/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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