Last active
August 29, 2015 13:56
-
-
Save lawrencegripper/9303955 to your computer and use it in GitHub Desktop.
Parallel Azure VM Script
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
$vms = Get-azurevm | ?{ $_.Status -eq "StoppedDeallocated"} | |
$jobs = @() | |
foreach ($vm in $vms) | |
{ | |
$params = @($vm.Name, $vm.ServiceName) | |
$job = Start-Job -ScriptBlock { | |
param($ComputerName, $ServiceName) | |
start-Azurevm -Name $ComputerName -ServiceName $ServiceName | |
} -ArgumentList $params | |
$jobs = $jobs + $job | |
} | |
# Wait for it all to complete | |
Wait-Job -Job $jobs | |
# Getting the information back from the jobs | |
Get-Job | Receive-Job |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated - @stuartleeks pointed out that I can used the Wait-Job Cmdlet instead of the nasty loop, great tip! Also I now pass in the specific list of jobs so won't affect other things using ps jobs on the machine.