Azure CLI Cheat Sheet: az login, Subscriptions, Resource Groups, VMs, AKS and --query
Checked against Azure CLI Azure CLI 2.93.0 (17 Nov 2026) on 28 November 2026. Each section links to the official docs it was checked against.
This sheet is for developers who manage Azure resources from a terminal and want the commands they repeat most in one place. It follows Microsoft Learn's Azure CLI docs and release notes as of 28 Nov 2026, when the latest release was 2.93.0. The az binary isn't available in my test shell, so rows are from the docs and marked untested.
When to use what
Sign in interactively with az login on your own machine and pick the subscription in the selector it shows. For automation, don't script a username and password: Microsoft's sign-in page says MFA is required for user identities on Azure CLI, so pipelines should use a service principal or managed identity instead.
Set the subscription explicitly with az account set at the top of any script, or pass --subscription per command. The CLI remembers your last choice, which is convenient by hand and dangerous in a script someone else runs.
For output, --output tsv plus a --query that names fields in order is the way to fill shell variables; the docs show az account show --query id --output tsv for exactly this. Use table to read, json to parse, and none for commands that print secrets you don't want in CI logs.
Resource groups are the unit of cleanup. Put everything for an experiment in one group and az group delete --yes --no-wait removes it all. For VMs, deallocate is the command that stops compute charges according to its reference entry. If an AI agent will run these, see the Azure MCP server and the Azure DevOps MCP server; our MCP servers for cloud infrastructure post compares the cloud options. The JSON formatter helps when you need to read raw az JSON.
az loginInteractive sign-in (browser on macOS and Linux, WAM on Windows) followed by a subscription selector
az login --use-device-codeForce the device code flow when no browser can open
az login --tenant 00000000-0000-0000-0000-000000000000Sign in to a specific tenant by ID or .onmicrosoft.com domain
az config set core.login_experience_v2=offTurn off the subscription selector shown after login
az account set --subscription "<name or id>"Make a subscription the default for later commands
az account show --query id --output tsvPrint just the active subscription ID for a script
Source: https://learn.microsoft.com/en-us/cli/azure/format-output-azure-cli
az account get-access-tokenGet a bearer token for the active subscription; prefer the expires_on UTC field
az logoutSign out of the CLI
--output accepts json (default), jsonc, table, tsv, yaml, yamlc and none. Table output hides keys like id, type and etag unless you rename them in --query.
az account list --query "[?isDefault].name"Filter an array with a predicate and keep one field
az vm show -g QueryDemo -n TestVM --query "{VMName:name, admin:osProfile.adminUsername}"Multiselect hash: pick and rename fields
az vm list -g QueryDemo --query "[?storageProfile.osDisk.osType=='Linux'].{Name:name}" --output tableFilter by a nested field and show a table
az vm list -g QueryDemo --query "sort_by([].{Name:name, Size:storageProfile.osDisk.diskSizeGb}, &Size)"Sort projected results by a field
az vm list --output tsv --query '[].[id, location, resourceGroup, name]'Fix the column order for TSV, which otherwise isn't guaranteed
Source: https://learn.microsoft.com/en-us/cli/azure/format-output-azure-cli
az config set core.output=tableChange the default output format for every command
Source: https://learn.microsoft.com/en-us/cli/azure/format-output-azure-cli
--output nonePrint nothing but errors and warnings, useful for commands that return secrets
Source: https://learn.microsoft.com/en-us/cli/azure/format-output-azure-cli
az group create -l westus -n MyResourceGroupCreate a group in a region
az group list --query "[?location=='westus']"List groups in one region
az group exists -n MyResourceGroupReturn true or false without failing
az group delete --name MyResourceGroup --no-wait --yesDelete the group and everything in it without prompting or waiting
Source: https://learn.microsoft.com/en-us/azure/aks/learn/quick-kubernetes-deploy-cli
az group wait --deleted --resource-group MyResourceGroupBlock until the deletion finishes, polling every 30 seconds by default
az vm create --resource-group $RG --name $VM --image $IMAGE --admin-username azureuser --generate-ssh-keys --public-ip-sku StandardCreate a Linux VM; reuses or generates a key in ~/.ssh
az vm show --show-details -g $RG -n $VM --query publicIps --output tsvGet a VM's public IP for ssh
az vm list -g MyResourceGroup -dList VMs with IPs, FQDN and power state; slower than without -d
Source: https://learn.microsoft.com/en-us/cli/azure/vm
az vm deallocate --name MyVm --resource-group MyResourceGroup --no-waitRelease compute so charges stop; status becomes Stopped (Deallocated)
Source: https://learn.microsoft.com/en-us/cli/azure/vm
az aks create --resource-group $RG --name $CLUSTER --node-count 1 --generate-ssh-keysCreate a one-node AKS cluster; it defaults to three nodes without --node-count
Source: https://learn.microsoft.com/en-us/azure/aks/learn/quick-kubernetes-deploy-cli
az aks get-credentials --resource-group $RG --name $CLUSTERMerge the cluster's credentials into your kubeconfig for kubectl
Source: https://learn.microsoft.com/en-us/azure/aks/learn/quick-kubernetes-deploy-cli
az aks nodepool add --resource-group $RG --cluster-name $CLUSTER --name userpool1 --node-count 1 --mode UserAdd a user node pool for application workloads
Source: https://learn.microsoft.com/en-us/azure/aks/learn/quick-kubernetes-deploy-cli
Extensions install under $AZURE_EXTENSION_DIR, by default ~/.azure/cliextensions, and update separately from the CLI.
az extension list-available --output tableBrowse Microsoft-maintained extensions
az extension add --name <extension-name>Install an extension by name
az extension update --name <extension-name>Update one extension; extensions are not updated along with the CLI
az extension remove --name <extension-name>Uninstall an extension
az config set extension.use_dynamic_install=yes_without_promptInstall missing extensions automatically when you run their commands
Worked example: Spin up a throwaway AKS cluster and tear it down
You need a cluster for an afternoon of testing, in its own group so cleanup is one command.
az account set --subscription "Dev"
export RG=aks-test-rg CLUSTER=aks-test LOCATION=westus2
az group create --name $RG --location $LOCATION
az aks create --resource-group $RG --name $CLUSTER --node-count 1 --generate-ssh-keys
az aks show --resource-group $RG --name $CLUSTER --query provisioningState --output tsv
az aks get-credentials --resource-group $RG --name $CLUSTER
kubectl get nodes
# when finished
az group delete --name $RG --no-wait --yes
I couldn't run az here, so here is what to check rather than captured output. az aks show ... --output tsv should print a bare Succeeded; tsv removes the quotes, so you can compare it in a shell if. get-credentials merges a context into your kubeconfig, and kubectl get nodes should then list one node in Ready state. The quickstart notes AKS creates a second, managed resource group for the node resources; deleting your group cleans that up too.
If az aks create fails on a fresh subscription, the quickstart says you may need to register the Microsoft.ContainerService provider first with az provider register.
Common mistakes
Scripting
az login -u user -p passwordin CI.That fails for MFA-enabled accounts, and MFA is now required for user identities. Use a service principal or managed identity.
Assuming
az vm stopstops the bill.The VM reference says
deallocateis what releases compute so charges no longer apply. Useaz vm deallocate.Assigning
$(az ... --query id)to a variable and getting a quoted string.Add
--output tsv, which prints the bare value without JSON quotes.Parsing plain
--output tsvcolumns by position.Column order isn't guaranteed. Use
--query '[].[a, b, c]'to fix the order.Using
az webapp upin new deployment scripts.Azure CLI 2.93.0 deprecates it. Plan to replace it with explicit create and deploy steps before it is removed.
Running commands against whatever subscription you used last.
Start scripts with
az account set --subscriptionor pass--subscriptionon each command.
Related cheat sheets
Sources
- https://learn.microsoft.com/en-us/cli/azure/authenticate-azure-cli-interactively
- https://learn.microsoft.com/en-us/cli/azure/query-azure-cli
- https://learn.microsoft.com/en-us/cli/azure/format-output-azure-cli
- https://learn.microsoft.com/en-us/cli/azure/group
- https://learn.microsoft.com/en-us/cli/azure/azure-cli-extensions-overview
- https://learn.microsoft.com/en-us/azure/virtual-machines/linux/quick-create-cli
- https://learn.microsoft.com/en-us/cli/azure/vm
- https://learn.microsoft.com/en-us/azure/aks/learn/quick-kubernetes-deploy-cli
- https://learn.microsoft.com/en-us/cli/azure/release-notes-azure-cli
How we research: where our facts come from, how often we re-check them, and why no one can pay for a review or a verdict.