Azure CLI Cheat Sheet

Manage Azure resources — login with a service principal, query with JMESPath, and drive VMs, AKS, and storage.

Cloud6 sections · 32 commands
⌘K

Login & Auth

7
az login

Interactive device-code login

az login --tenant TENANT_ID

Log in to a specific tenant

az account show

Current subscription

az account list -o table

Accessible subscriptions

az account set --subscription SUB

Switch subscriptions

az login --service-principal -u APP_ID -p SECRET --tenant TENANT

Service principal login (CI)

az logout

Clear cached tokens

Resource Groups

4
az group list -o table

All resource groups

az group create --name RG --location eastus

Create a resource group

az group delete --name RG --yes --no-wait

Delete a group and its resources

az group show --name RG

Group metadata

Virtual Machines

7
az vm list -o table

VMs and their state

az vm list-ip-addresses --name VM --resource-group RG

Public/private IPs

az vm start/stop/restart --name VM --resource-group RG

Power actions

az vm deallocate --name VM --resource-group RG

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

Available Ubuntu images

AKS & Containers

4
az aks get-credentials --name CLUSTER --resource-group RG

Merge into kubeconfig

az aks list --output table

Managed clusters

az aks upgrade --name C --resource-group RG --kubernetes-version V --yes

Upgrade the cluster

az acr login --name REGISTRY

Login to Azure Container Registry

Storage

6
az storage account list -o table

Storage accounts

az storage blob list --account-name ACCOUNT --container-name C

List blobs

az storage blob upload --account-name ACCOUNT --container-name C --name file --file ./file --auth-mode login

Upload a blob

az storage blob download --account-name ACCOUNT --container-name C --name file --file out --auth-mode login

Download a blob

az storage container create --name C --account-name ACCOUNT --auth-mode login

Create a container

az storage account keys list -g RG -n ACCOUNT

List access keys

Querying

4
az resource list --tag env=prod --query "[?type=='Microsoft.Compute/virtualMachines'].name" -o tsv

JMESPath filter with tags

az vm list -o json --query '[].{name:name,size:hardwareProfile.vmSize}'

Project the fields you want

az find az vm

Get examples for a command

az interactive

Interactive CLI with autocomplete