Skip to content

Menu

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 login

Interactive sign-in (browser on macOS and Linux, WAM on Windows) followed by a subscription selector

From the docs, not run by us
az login --use-device-code

Force the device code flow when no browser can open

From the docs, not run by us
az login --tenant 00000000-0000-0000-0000-000000000000

Sign in to a specific tenant by ID or .onmicrosoft.com domain

From the docs, not run by us
az config set core.login_experience_v2=off

Turn off the subscription selector shown after login

From the docs, not run by us
az account set --subscription "<name or id>"

Make a subscription the default for later commands

From the docs, not run by us
az account show --query id --output tsv

Print just the active subscription ID for a script

Source: https://learn.microsoft.com/en-us/cli/azure/format-output-azure-cli

From the docs, not run by us
az account get-access-token

Get a bearer token for the active subscription; prefer the expires_on UTC field

From the docs, not run by us
az logout

Sign out of the CLI

From the docs, not run by us

--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

From the docs, not run by us
az vm show -g QueryDemo -n TestVM --query "{VMName:name, admin:osProfile.adminUsername}"

Multiselect hash: pick and rename fields

From the docs, not run by us
az vm list -g QueryDemo --query "[?storageProfile.osDisk.osType=='Linux'].{Name:name}" --output table

Filter by a nested field and show a table

From the docs, not run by us
az vm list -g QueryDemo --query "sort_by([].{Name:name, Size:storageProfile.osDisk.diskSizeGb}, &Size)"

Sort projected results by a field

From the docs, not run by us
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

From the docs, not run by us
az config set core.output=table

Change the default output format for every command

Source: https://learn.microsoft.com/en-us/cli/azure/format-output-azure-cli

From the docs, not run by us
--output none

Print nothing but errors and warnings, useful for commands that return secrets

Source: https://learn.microsoft.com/en-us/cli/azure/format-output-azure-cli

From the docs, not run by us
az group create -l westus -n MyResourceGroup

Create a group in a region

From the docs, not run by us
az group list --query "[?location=='westus']"

List groups in one region

From the docs, not run by us
az group exists -n MyResourceGroup

Return true or false without failing

From the docs, not run by us
az group delete --name MyResourceGroup --no-wait --yes

Delete the group and everything in it without prompting or waiting

Source: https://learn.microsoft.com/en-us/azure/aks/learn/quick-kubernetes-deploy-cli

From the docs, not run by us
az group wait --deleted --resource-group MyResourceGroup

Block until the deletion finishes, polling every 30 seconds by default

From the docs, not run by us
az vm create --resource-group $RG --name $VM --image $IMAGE --admin-username azureuser --generate-ssh-keys --public-ip-sku Standard

Create a Linux VM; reuses or generates a key in ~/.ssh

From the docs, not run by us
az vm show --show-details -g $RG -n $VM --query publicIps --output tsv

Get a VM's public IP for ssh

From the docs, not run by us
az vm list -g MyResourceGroup -d

List VMs with IPs, FQDN and power state; slower than without -d

Source: https://learn.microsoft.com/en-us/cli/azure/vm

From the docs, not run by us
az vm deallocate --name MyVm --resource-group MyResourceGroup --no-wait

Release compute so charges stop; status becomes Stopped (Deallocated)

Source: https://learn.microsoft.com/en-us/cli/azure/vm

From the docs, not run by us
az aks create --resource-group $RG --name $CLUSTER --node-count 1 --generate-ssh-keys

Create 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

From the docs, not run by us
az aks get-credentials --resource-group $RG --name $CLUSTER

Merge the cluster's credentials into your kubeconfig for kubectl

Source: https://learn.microsoft.com/en-us/azure/aks/learn/quick-kubernetes-deploy-cli

From the docs, not run by us
az aks nodepool add --resource-group $RG --cluster-name $CLUSTER --name userpool1 --node-count 1 --mode User

Add a user node pool for application workloads

Source: https://learn.microsoft.com/en-us/azure/aks/learn/quick-kubernetes-deploy-cli

From the docs, not run by us

Extensions install under $AZURE_EXTENSION_DIR, by default ~/.azure/cliextensions, and update separately from the CLI.

az extension list-available --output table

Browse Microsoft-maintained extensions

From the docs, not run by us
az extension add --name <extension-name>

Install an extension by name

From the docs, not run by us
az extension update --name <extension-name>

Update one extension; extensions are not updated along with the CLI

From the docs, not run by us
az extension remove --name <extension-name>

Uninstall an extension

From the docs, not run by us
az config set extension.use_dynamic_install=yes_without_prompt

Install missing extensions automatically when you run their commands

From the docs, not run by us

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 password in 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 stop stops the bill.

    The VM reference says deallocate is what releases compute so charges no longer apply. Use az 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 tsv columns by position.

    Column order isn't guaranteed. Use --query '[].[a, b, c]' to fix the order.

  • Using az webapp up in 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 --subscription or pass --subscription on each command.