One-Liner: Stop and Deallocate Azure Virtual Machines
Here's something I do a lot. As I do it a lot, I thought others might also find it useful.
I run a number of cloud services in Windows Azure via my MSDN subscription. This subscription gives me a set amount per month to spend on VMs. As it's a set amount, I have to be careful when it comes to usage.
After a day of Azure frolics, I use the following one-liner to stop and deallocate running VMs from all my cloud services. This ensures I don't incur any unnecessary compute charges - if you don't deallocate, you're still paying!
Get-AzureVM |
Where-Object {$_.status -ne "StoppedDeallocated"} |
Stop-AzureVM -Force
Now, I'm usually pretty good at remembering to stop and deallocate, but if you're a little forgetful, you could set up a runbook to take care of the task for you. A runbook provides the scheduled execution of a PowerShell workflow. I guess I should write a follow up post!