Skip to content
Latchkey

az vm list: Query, Output & Common CI Errors

List Azure virtual machines - filtered and formatted with JMESPath.

az vm list returns the VMs in your subscription or a resource group. Like other Azure CLI list commands, you shape the output with --query (JMESPath) and -o to get exactly what a script needs.

What it does

az vm list returns VM resource objects; add --resource-group to scope to one group. The response is verbose, so --query extracts fields (name, location, powerState) and -o table/tsv formats them. For runtime power state, add -d (show-details) since the base list does not include it.

Common usage

Terminal
# List all VMs as a name/location table
az vm list --query "[].{name:name, rg:resourceGroup, loc:location}" -o table

# VMs in one resource group
az vm list --resource-group my-rg -o table

# Include power state (requires -d / --show-details)
az vm list -d --query "[].{name:name, power:powerState}" -o table

Common error in CI: empty output / powerState always null

You get an empty list because the active subscription is wrong (the VMs live elsewhere), or powerState is null because you queried it without -d. Fix: select the right subscription first (az account set --subscription <id>), and pass -d/--show-details when you need runtime fields like powerState (it makes an extra call per VM, so it is slower). Quote the entire --query expression so the shell passes it as one argument.

Key options

OptionPurpose
--resource-group / -gScope to one resource group
-d, --show-detailsInclude runtime info (powerState, IPs)
--queryJMESPath to extract fields
-o table|tsv|jsonOutput format

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →