Skip to content

Instantly share code, notes, and snippets.

@lawrencegripper
Last active August 29, 2015 13:56
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 lawrencegripper/9303955 to your computer and use it in GitHub Desktop.
Save lawrencegripper/9303955 to your computer and use it in GitHub Desktop.
Parallel Azure VM Script
$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
@lawrencegripper
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment