Get Azure Virtual Machine Status With PowerShell

Checking the status of a Virtual Machine running on Microsoft Azure using PowerShell is helpful in scenarios where you need to verify the status of the VM before taking action.

Az PowerShell Module

The current and official PowerShell module for Azure is the Az Module and you can install it on Windows, Linux, macOS and Cloud Shell. The module gets updated regularly with new cmdlets and bug fixes.

In our case, we will use the get-azvm cmdlet to get the status of the VM. In Azure, the status is visible under the powerstate property.

The following cmdlet will get the status of all the VMs and will show if they are running or stopped (deallocated).

get-azvm -Status | select name, powerstate

To check the status of a specific virtual machine we use the following cmdlet.

get-azvm -Status -ResourceGroupName RG -Name VMNAME

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.