Skip to content

Instantly share code, notes, and snippets.

@morgansimonsen
Created January 20, 2014 21:13
Show Gist options
  • Save morgansimonsen/8529297 to your computer and use it in GitHub Desktop.
Save morgansimonsen/8529297 to your computer and use it in GitHub Desktop.
# Control-AzureVMs.ps1
# Shut down or start a set of Windows Azure VMs in sequence
# v0.1 2014-01-20
#
# Morgan Simonsen
# www.cloudpower.no
# morgansimonsen.wordpress.com
Select-AzureSubscription "<subscription name>"
If ($args[1] -eq $null)
{ $VMs = Get-Content (Join-Path $PSScriptRoot "Control-AzureVMs.txt")}
Else
{ $VMs = Get-Content $args[1] }
Switch ($args[0])
{
Stop
{
[array]::Reverse($VMs) # Must shut down in reverse order
$VMs | ForEach `
{
$VM = $_ -split ";"
Write-Host "Stopping VM:"$VM[1]
Stop-AzureVM -ServiceName $VM[0] -Name $VM[1] -Force
}
}
Start
{
$VMs | ForEach `
{
$VM = $_ -split ";"
Write-Host "Starting VM:"$VM[1]
Start-AzureVM -ServiceName $VM[0] -Name $VM[1]
$VMStatus = Get-AzureVM -ServiceName $VM[0] -Name $VM[1]
While ($VMStatus.InstanceStatus -ne "ReadyRole")
{
write-host " Waiting...Current Status = " $VMStatus.Status
Start-Sleep -Seconds 15
$VMStatus = Get-AzureVM -ServiceName $VM[0] -name $VM[1]
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment