View status of ARM VMs using PowerShell

Q. How can I view the status of my ARM VMs using PowerShell?

A. To view the status of an Azure RM VM using PowerShell you must add the -Status parameter which includes an array of statuses, one of which is the current powerstate., e.g.

Get-AzureRmVM -ResourceGroupName "SAVILLTECHRGEASTUS" -Name "testvm44" -Status

To view the status for all VMs you could use something like the following:

$RGs = Get-AzureRMResourceGroup
foreach($RG in $RGs)
{
    $VMs = Get-AzureRmVM -ResourceGroupName $RG.ResourceGroupName
    foreach($VM in $VMs)
    {
        $VMDetail = Get-AzureRmVM -ResourceGroupName $RG.ResourceGroupName -Name $VM.Name -Status
        foreach ($VMStatus in $VMDetail.Statuses)
        { 
            if($VMStatus.Code.CompareTo("PowerState/deallocated") -eq 0)
            {
                $VMStatusDetail = $VMStatus.DisplayStatus
            }
        }
        write-output $VM.Name $VMStatusDetail
    }
}

Basically in the above PowerShell I go through all resource groups for all VMs and for each find the status related to power state then output.

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish