Azure
The Azure CLI commands for sign-in, groups, storage, VMs, networks, access, Key Vault, templates and clean-up, with the options you forget.
Sign in and context
az loginSign in (browser or device code on a real machine)
az account show --query name -o tsvThe name of the active subscription, as plain text
az account list -o tableEvery subscription you can use, and which one is the default
az account set --subscription "Dev Sandbox"Make another subscription the default (name or id)
az account list-locations --query "[].name" -o tsvThe region names you can use with --location
az configure --defaults group=rg-app location=centralindiaSave a default resource group and region
az configure --list-defaultsSee which defaults are set
az logoutSign out
Output and --query
az group list -o tableA readable table (json is the default)
az group list --query "[].name" -o tsvOne value per line, ready for scripts
az resource list --query "[?type=='Microsoft.Storage/storageAccounts'].name" -o tsvFilter with a JMESPath condition
az vm list --query "[].{name:name, size:hardwareProfile.vmSize}" -o tableRename and pick fields into a new object
az vm list-sizes --query "length(@)" -o tsvCount the items of a result
az group show -n rg-app -o yamlThe same data as YAML
az <group> <command> --helpOptions and examples for any command
Resource groups and tags
az group create -n rg-app -l centralindia --tags env=dev owner=ashaCreate a resource group with tags
az group update -n rg-app --set tags.costcenter=cc-1042Change one tag (--tags replaces the whole set)
az group list --tag env=test --query "[].name" -o tsvFind groups by tag
az group exists -n rg-appPrints true or false
az resource list -g rg-app -o tableEverything inside a group
az resource tag --tags costcenter=training --ids $(az resource list -g rg-app --query "[].id" -o tsv)Tag many resources at once
az group delete -n rg-app --yes --no-waitDelete the group and everything in it
Storage
az storage account check-name --name labstore42xIs the (globally unique) name free and valid?
az storage account create -n labstore42x -g rg-app --sku Standard_LRS --kind StorageV2Create a storage account
az storage container create -n docs --account-name labstore42xCreate a private container
az storage blob upload -c docs -f a.txt -n a.txt --account-name labstore42x --auth-mode loginUpload one file, authorised by your Microsoft Entra identity
az storage blob upload-batch -s site -d docs --destination-path site --account-name labstore42xUpload a whole folder
az storage blob list -c docs --account-name labstore42x --query "[].name" -o tsvList blob names
az storage blob download -c docs -n a.txt -f copy.txt --account-name labstore42xDownload a blob
az storage blob generate-sas -c docs -n a.txt --permissions r --expiry 2030-01-01T00:00Z --full-uri --account-name labstore42xA read-only link that expires
Virtual machines
az vm create -g rg-vm -n vm-web --image Ubuntu2204 --size Standard_B1s --generate-ssh-keysCreate a Linux VM and its disk, NIC, IP and NSG
az vm list -d -o tableVMs with power state and public IP
az vm show -d -g rg-vm -n vm-web --query publicIps -o tsvThe public IP address only
az vm stop -g rg-vm -n vm-webPower off (still billed for compute)
az vm deallocate -g rg-vm -n vm-webRelease compute so billing stops
az vm start -g rg-vm -n vm-webStart it again
az vm resize -g rg-vm -n vm-web --size Standard_B2sChange the size
az vm delete -g rg-vm -n vm-web --yesDelete the VM (its disk, NIC and IP stay)
Virtual networks and NSGs
az network vnet create -g rg-net -n vnet-hub --address-prefixes 10.10.0.0/16 --subnet-name snet-web --subnet-prefixes 10.10.1.0/24A virtual network with its first subnet
az network vnet subnet create -g rg-net --vnet-name vnet-hub -n snet-app --address-prefixes 10.10.2.0/24Add a subnet
az network vnet update -g rg-net -n vnet-hub --address-prefixes 10.10.0.0/16 10.11.0.0/16Change the address space (give the whole list)
az network nsg create -g rg-sec -n nsg-webA network security group
az network nsg rule create -g rg-sec --nsg-name nsg-web -n allow-https --priority 100 --protocol Tcp --destination-port-ranges 443Allow HTTPS in (lower priority number is checked first)
az network nsg rule list -g rg-sec --nsg-name nsg-web --include-default -o tableYour rules and the built-in ones
az network vnet subnet update -g rg-sec --vnet-name vnet-app -n snet-web --network-security-group nsg-webAttach an NSG to a subnet
Roles and access
az role definition list --name Reader --query "[0].permissions[0].actions"What a built-in role allows
az ad signed-in-user show --query id -o tsvYour own object id
az role assignment create --assignee user@contoso.com --role Reader --scope $(az group show -n rg-app --query id -o tsv)Give a role at a resource group scope
az role assignment list --scope <id> -o tableWho has what at a scope
az role assignment delete --assignee user@contoso.com --role Reader --scope <id>Take access away
Key Vault
az keyvault create -n kvlab-42x -g rg-vault -l centralindiaCreate a vault (RBAC authorization is the default)
az role assignment create --assignee <id> --role "Key Vault Secrets Officer" --scope $(az keyvault show -n kvlab-42x --query id -o tsv)Allow yourself to read and write secrets
az keyvault secret set --vault-name kvlab-42x -n db-password --value '...' --expires 2030-12-31T00:00:00ZStore a secret (setting again adds a version)
az keyvault secret show --vault-name kvlab-42x -n db-password --query value -o tsvRead the value
az keyvault secret list-versions --vault-name kvlab-42x -n db-password -o tableEvery version of a secret
az keyvault secret delete --vault-name kvlab-42x -n db-passwordSoft delete (recoverable)
az keyvault secret recover --vault-name kvlab-42x -n db-passwordBring a deleted secret back
Template deployments
az deployment group validate -g rg-iac --template-file azuredeploy.jsonCheck a template without deploying it
az deployment group what-if -g rg-iac --template-file azuredeploy.jsonPreview Create (+), Modify (~) and Delete (-)
az deployment group create -g rg-iac --template-file azuredeploy.json --parameters @dev.parameters.jsonDeploy with a parameters file
az deployment group create -g rg-iac -f t.json --parameters env=prod sku=Standard_GRSPass single parameters as name=value
az deployment group create -g rg-iac -f t.json --mode CompleteAlso delete anything not in the template (run what-if first)
az deployment group show -g rg-iac -n azuredeploy --query properties.outputsRead a deployment's outputs
az deployment group list -g rg-iac -o tableDeployment history
Locks and clean-up
az lock create -n keep --lock-type CanNotDelete -g rg-prod --resource-name mystore --resource-type Microsoft.Storage/storageAccountsProtect one resource from deletion
az lock list -o tableAll locks in the subscription
az lock delete -n keep -g rg-prod --resource-name mystore --resource-type Microsoft.Storage/storageAccountsRemove a lock
az disk list --query "[?managedBy==null].name" -o tsvDisks no VM uses
az resource list --query "[?tags.costcenter==null].name" -o tsvResources missing a cost tag
az keyvault list-deleted -o tableSoft-deleted vaults that still hold their name
Nothing matches that search.
Cheatsheet for the Azure path · Deboistech · All cheatsheets
