Shut down an Azure VM

To save running costs, it’s wise to deallocate an Azure VM. Shut down the operating system alone does not stop the billable charges for the compute aspect of the VM; therefore, you should stop the VM, which deallocates the resources associated to it at the hypervisor level. Whilst you won’t be billed for the compute, other resources still incur costs, including:

There are a few simple ways to shut down and deallocate a VM, namely through the Azure Portal on your computer or anywhere if you have the Azure mobile app.
For a more automated approach, you could schedule the VM to shutdown by specifying a time under the ‘Auto-shutdown’ blade under Options, or have the VM start up and shut down during certain times of the day using Azure Automation.

Sometimes VM's can refuse to shut down for various reasons, including the guest operating system might not be responding, an extension install is stuck in a transitioning state or an issue with the API call to deallocate the VM though the portal or app. In these circumstances, you might need to shut down the VM using alternative ways.

To shut down a VM from the Azure CLI or Az PowerShell on your computer or via the Cloud Shell within the Azure Portal:


az vm deallocate --name MyVM1 --no-wait --resource-group Servers


Stop-AzVM -ResourceGroupName "Servers" -Name "MyVM1" -Force

You can select the ‘Redeploy’ blade under ‘Support + troubleshooting’. This will relocate the VM to another host, essentially having to shut down the guest in the process. This option may fail if the VM is in an unresponsive state.

Another option is to resize the VM to a higher VM size; this forces the VM to power off as it needs to move it onto another hypervisor. It's kind of ‘last resort’ option, but handy especially if the VM incurs a high running cost and you can always resize back to its original size after.

Finally, if you are patient enough, wait for the shutdown to time out and re-try issuing another shutdown request after.