Created
June 28, 2016 19:50
-
-
Save davops/95461ad6503b977b282739ab224767f5 to your computer and use it in GitHub Desktop.
Using PowerShell, start background jobs on multiple servers at the same time and wait until they finish.
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
#Purpose: Start background jobs on multiple servers at the same time and wait until they finish | |
$servers = "server1","server2","server3" | |
$buildNumber = "1.2" | |
$servers | %{ | |
$script = | |
{ | |
param($server) | |
Invoke-Command -ComputerName $server -ScriptBlock {param($buildNumber) New-Item c:\Deployment\$buildNumber -type directory -force} | |
Invoke-Command -ComputerName $server -ScriptBlock {param($server) Start-Process -Wait -Filepath "C:\Deployment\Deployment_Script.exe" -RedirectStandardOutput "c:\deployment\output_$server.txt"} -Args $server | |
} | |
Start-Job $script -ArgumentList $_ #refers to the $server variable | |
} | |
While(Get-Job -State "Running"){Start-Sleep 30} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment