Skip to main content
Azure CLI Reference

az vm list: Azure CLI Command Reference, Syntax, Examples

az vm list is the Azure CLI command to list virtual machines in a subscription or resource group, supporting --query and --show-details for power state and public IPs.

az vm list [--resource-group] [--show-details] [--query] [--output] [--subscription]

Options and Flags

Flag Type Default Description
--resource-group -g String All resource groups Name of the resource group. If omitted, lists VMs across all accessible groups.
--show-details -d Switch False Display power state, public IPs, and private IPs for each VM.
--query String None JMESPath query to filter and format output (e.g., [].name).
--output -o String json (for table: table) Output format: json, jsonc, table, tsv, yaml, yamlc.
--subscription String Default subscription Name or ID of the subscription. Overrides az account set context.

Usage Examples

List all VMs in a subscription

az vm list --output table

Outputs a table with Name, ResourceGroup, Location, Zones. When the subscription contains hundreds of VMs, use --query to limit fields and speed up output.

See also  Windows CMD Uptime: CLI Commands, Syntax & Examples

List VMs with power state and IPs for a specific resource group

az vm list -g Production --show-details --query "[].{Name:name, State:powerState, PublicIP:publicIps}" -o table

Inspects all VMs in the ‘Production’ resource group, mapping power state and public IPs. Critical for automating status checks in CI/CD pipelines.

List all deallocated VMs across all resource groups

az vm list -d --query "[?powerState=='VM deallocated'].{Name:name, RG:resourceGroup}" -o tsv

Identifies stopped (deallocated) VMs that still incur disk storage costs. Combine with az vm start or az vm delete in automation scripts to optimize costs.

Troubleshooting & Common Errors

Error Message / Code Root Cause Resolution Command
ResourceGroupNotFound Specified resource group does not exist or user lacks reader access. az vm list -g MyGroup → verify group name with az group list --query "[?name=='MyGroup']" or check permissions.
AuthorizationFailed Service principal or user lacks Microsoft.Compute/virtualMachines/read permission. Use az role assignment list --assignee <principal-id> --scope /subscriptions/<sub> --output table and assign Reader role if missing.
SubscriptionNotFound Subscription ID is incorrect or not accessible. az account set --subscription "SubscriptionName" or az account list --output table to verify.
Empty output (no VMs) No VMs in the subscription or resource group, or query filtering incorrectly. Remove the --query or --resource-group to see all VMs: az vm list -o table.

Exit Codes

Code Meaning Operational Impact
0 Success Command completed and output produced (or empty list).
1 Generic error / invalid request Check subscription, resource group, or authentication. Frequent cause: SubscriptionNotFound.
2 Usage error / invalid flag Review syntax. Example: az vm list --unknown.

Frequently Asked Questions

What is the difference between az vm list --resource-group and az vm list without the flag?

Answer: Without --resource-group, az vm list returns all VMs across all resource groups in the current subscription. Using no scope increases latency for large subscriptions due to broader API calls. Narrowing to a resource group reduces network overhead and query time.

az vm list --resource-group MyRG --output table

When should I use the --show-details flag with az vm list?

Answer: Use --show-details when you need power state, provisioning state, and VM size for every VM in a single command without additional API calls. Default output omits these fields to reduce response size. --show-details triggers a separate per-VM call, increasing execution time. Prefer --query for targeted properties.

az vm list --show-details --query "[].{Name:name, PowerState:powerState}" -o table

How do I fix the AuthorizationFailed error when running az vm list?

Answer: Reauthenticate with az login and verify correct subscription with az account set --subscription "...". However, the root cause is typically insufficient permissions or expired token. Use az role assignment list --assignee <principal-id> --scope /subscriptions/<sub> --output table to check roles; assign the Reader role if missing. For cross-subscription access, run az account list --all to confirm available tenants and subscriptions.

az account set --subscription "Production-Sub"
az vm list --output table

Does az vm list work on Microsoft Azure Stack Hub?

Answer: No. The az CLI is designed for global Azure and Azure Stack Edge/HCI. For Azure Stack Hub, install the AzureRM module (not the Az module) in PowerShell.

# Unsupported – will throw 'ResourceNotFound'
az vm list --resource-group MyStackRG
# Correct approach in PowerShell:
Get-AzureRMVM -ResourceGroupName MyStackRG

What is the fastest way to list all VM names and their resource groups across multiple subscriptions with az vm list?

Answer: Use a loop over subscription IDs from az account list. Avoid --show-details to minimize overhead.

for sub in $(az account list --query "[].id" -o tsv); do
  az vm list --subscription "$sub" --query "[].{Name:name, RG:resourceGroup}" -o tsv
done > all_vms_quick.tsv