Azure CLI Cheat Sheet
Manage Azure resources — login with a service principal, query with JMESPath, and drive VMs, AKS, and storage.
Login & Auth
7az loginInteractive device-code login
az login --tenant TENANT_IDLog in to a specific tenant
az account showCurrent subscription
az account list -o tableAccessible subscriptions
az account set --subscription SUBSwitch subscriptions
az login --service-principal -u APP_ID -p SECRET --tenant TENANTService principal login (CI)
az logoutClear cached tokens
Resource Groups
4az group list -o tableAll resource groups
az group create --name RG --location eastusCreate a resource group
az group delete --name RG --yes --no-waitDelete a group and its resources
az group show --name RGGroup metadata
Virtual Machines
7az vm list -o tableVMs and their state
az vm list-ip-addresses --name VM --resource-group RGPublic/private IPs
az vm start/stop/restart --name VM --resource-group RGPower actions
az vm deallocate --name VM --resource-group RGStop and release the hardware
az vm show --name VM --resource-group RG --query 'osProfile.linuxConfiguration'Inspect VM config
az vm run-command invoke -g RG -n VM --command-id RunShellScript --scripts 'uptime'Run a command on the VM
az vm image list --offer UbuntuServer --allAvailable Ubuntu images
AKS & Containers
4az aks get-credentials --name CLUSTER --resource-group RGMerge into kubeconfig
az aks list --output tableManaged clusters
az aks upgrade --name C --resource-group RG --kubernetes-version V --yesUpgrade the cluster
az acr login --name REGISTRYLogin to Azure Container Registry
Storage
6az storage account list -o tableStorage accounts
az storage blob list --account-name ACCOUNT --container-name CList blobs
az storage blob upload --account-name ACCOUNT --container-name C --name file --file ./file --auth-mode loginUpload a blob
az storage blob download --account-name ACCOUNT --container-name C --name file --file out --auth-mode loginDownload a blob
az storage container create --name C --account-name ACCOUNT --auth-mode loginCreate a container
az storage account keys list -g RG -n ACCOUNTList access keys
Querying
4az resource list --tag env=prod --query "[?type=='Microsoft.Compute/virtualMachines'].name" -o tsvJMESPath filter with tags
az vm list -o json --query '[].{name:name,size:hardwareProfile.vmSize}'Project the fields you want
az find az vmGet examples for a command
az interactiveInteractive CLI with autocomplete