Created
July 28, 2015 14:38
-
-
Save Kevin-Bronsdijk/6b5767db18acd63a199d to your computer and use it in GitHub Desktop.
automatically-deallocate-azure-vms
This file contains hidden or 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
workflow Test | |
{ | |
$Cred = Get-AutomationPSCredential -Name "auto" | |
Add-AzureAccount -Credential $Cred | |
Get-AzureVM | |
} |
This file contains hidden or 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
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