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!


Comments (2)

  1. anonymouscommenter says:

    Recent Releases and Announcements

    SQL 2016 CTP 2.3 has been released

  2. Jan Ver says:

    Hey Ian,
    Looks useful, thx for sharing.
    Any chance we can have something similar to this with Get-AzureRmVM for ARM? I tried adjusting this script but was not able to adapt appropriately getting only errors or full lists in return.

Skip to main content