Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Kevin-Bronsdijk/6b5767db18acd63a199d to your computer and use it in GitHub Desktop.
Save Kevin-Bronsdijk/6b5767db18acd63a199d to your computer and use it in GitHub Desktop.
automatically-deallocate-azure-vms
workflow Test
{
$Cred = Get-AutomationPSCredential -Name "auto"
Add-AzureAccount -Credential $Cred
Get-AzureVM
}
workflow Shutdown
{
param([string]$startsWith)
$Cred = Get-AutomationPSCredential -Name "auto"
Add-AzureAccount -Credential $Cred
$vms = Get-azurevm
foreach ($vm in $vms)
{
if($vm.Name.StartsWith($startsWith) -and $vm.Status -eq "ReadyRole")
{
Stop-AzureVM -ServiceName $vm.ServiceName -Name $vm.Name -Force
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment