13

Azure CLI allows people to start & stop VMs.

However, is there any Azure CLI command that can show the VM status? I.e., whether it is started or being stopped? Thx.

Run5k
  • 16,463
  • 24
  • 53
  • 67
xpt
  • 9,385
  • 44
  • 120
  • 178

4 Answers4

25

You can use the '-d' flag with list and status for all VMs

az vm list -d -o table

For single VM, you can use:

az vm list -d -o table --query "[?name=='vm-name']"

If you need more specific results then you can also try:

az vm list -d --query "[?powerState=='VM running']" -o table
ironman
  • 366
9

You can get the vm status with this command:

az vm get-instance-view --name vmName --resource-group resourceGroupName --query instanceView.statuses[1] --output table

The output will like this:

enter image description here

2

You can also run query in Azure Resource Graph Explorer

Resources
| project name, location, 
   PowerState=tostring(properties.extended.instanceView.powerState.code), type
| where type =~ 'Microsoft.Compute/virtualMachines'
| order by name desc
volody
  • 135
1

all these answers did not work for me I had to use

az vm show -d --resource-group my-rsg-name --name my-vm-name --subscription my-subsciption-id --query "powerState"

this just shows: enter image description here