Check if a VM is stopped or deallocated from the Azure fabric with PowerShell.

With a few lines of PowerShell check if a VM is stopped (costing you money) or actually deallocated (not costing you money).

John Savill

August 5, 2016

1 Min Read
Check if a VM is stopped or deallocated from the Azure fabric with PowerShell.

Q. How can I check from PowerShell if a VM is shutdown or actually deallocated in Azure?

A. The Get-AzureRmVM cmdlet has a -Status parameter which shows a number of aspects related to the VM. An array of statuses are found for each VM and you need to look at the DisplayStatus attribute of the multiple statuses which do not have a code of ProvisioningState/succeeded. For example:

$VMDetail = Get-AzureRmVM -ResourceGroupName $RG.ResourceGroupName -Name $VM.Name -Statusforeach ($VMStatus in $VMDetail.Statuses){     if($VMStatus.Code.CompareTo("ProvisioningState/succeeded") -ne 0) #don't want to the provisioning status    {        $VMStatusDetail = $VMStatus.DisplayStatus    }}

If the VM is stopped but still provisioned on the Azure fabric (you are still paying) it will have a value of "VM stopped". If the VM is deprovisioned from the fabric it will have a value of "VM deallocated".

About the Author(s)

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like