Written for Azure CLI 2.70 and later. Names, IDs and regions are examples, so swap in your own, and add --subscription to any command to pick a subscription. A few commands need an extension, which the CLI offers to install the first time. Queries use double quotes outside and single quotes inside, which works in bash, zsh, PowerShell and Command Prompt.

Setup and help #

  • Show the Azure CLI version, and its extensionsLinux, macOS, Windows
    az version
  • Update the Azure CLI and its extensionsLinux, macOS, Windows
    az upgrade
  • List every command groupLinux, macOS, Windows
    az --help
  • Get help for one command, with examplesLinux, macOS, Windows
    az vm create --help
  • Find commands and examples for a taskLinux, macOS, Windows
    az find "create a storage account"
  • List installed extensionsLinux, macOS, Windows
    az extension list --output table
  • Install an extensionLinux, macOS, Windows
    az extension add --name ssh
  • Update every installed extensionLinux, macOS
    az extension list --query "[].name" --output tsv | xargs -n1 az extension update --name
  • Let the CLI install extensions when a command needs oneLinux, macOS, Windows
    az config set extension.use_dynamic_install=yes_without_prompt
  • Show your CLI settingsLinux, macOS, Windows
    az config get

Sign in and subscriptions #

  • Sign in in the browserLinux, macOS, Windows
    az login
  • Sign in on a machine with no browser, using a codeLinux, macOS, Windows
    az login --use-device-code
  • Sign in to a particular tenantLinux, macOS, Windows
    az login --tenant contoso.onmicrosoft.com
  • Sign in as a service principalLinux, macOS, Windows
    az login --service-principal --username 00000000-0000-0000-0000-000000000000 --password MyClientSecret --tenant contoso.onmicrosoft.com

    Warning: The secret ends up in your shell history. Use a certificate, or read the secret from an environment variable.

  • Sign in with the managed identity of the VM or service you're onLinux, macOS, Windows
    az login --identity
  • Sign outLinux, macOS, Windows
    az logout
  • Show which subscription and account you're usingLinux, macOS, Windows
    az account show --output table
  • List your subscriptionsLinux, macOS, Windows
    az account list --output table
  • Switch to another subscriptionLinux, macOS, Windows
    az account set --subscription "My Subscription"
  • Run one command in another subscriptionLinux, macOS, Windows
    az group list --subscription "My Subscription"
  • Show which tenant each subscription is inLinux, macOS, Windows
    az account list --all --query "[].{Subscription:name, Tenant:tenantId, State:state}" --output table
  • List the regions available to your subscriptionLinux, macOS, Windows
    az account list-locations --query "[].name" --output tsv
  • Get an access token for the Azure APILinux, macOS, Windows
    az account get-access-token --query accessToken --output tsv

    Warning: Prints a secret in plain text. Don't paste the output anywhere it could be saved or shared.

  • Get an access token for Microsoft GraphLinux, macOS, Windows
    az account get-access-token --resource-type ms-graph --query accessToken --output tsv

    Warning: Prints a secret in plain text. Don't paste the output anywhere it could be saved or shared.

  • Forget every saved sign-in and subscriptionLinux, macOS, Windows
    az account clear

Output, queries and defaults #

  • Show output as a tableLinux, macOS, Windows
    az vm list --output table
  • Show output as tab-separated text, for scriptsLinux, macOS, Windows
    az vm list --output tsv
  • Show output as YAMLLinux, macOS, Windows
    az vm list --output yaml
  • Show output as coloured JSONLinux, macOS, Windows
    az vm list --output jsonc
  • Show nothing on successLinux, macOS, Windows
    az group create --name my-rg --location westeurope --output none
  • Pick fields out of the output with a queryLinux, macOS, Windows
    az vm list --query "[].{Name:name, Group:resourceGroup, Location:location}" --output table
  • Keep only matching items with a queryLinux, macOS, Windows
    az vm list --query "[?location=='westeurope'].name" --output tsv
  • Keep items whose name contains some textLinux, macOS, Windows
    az resource list --query "[?contains(name, 'web')].[name,type]" --output table
  • Count the resultsLinux, macOS, Windows
    az vm list --query "length(@)"
  • Get one value for a scriptLinux, macOS, Windows
    az account show --query id --output tsv
  • Save one value in a variable
    Linux, macOS
    subscription_id=$(az account show --query id --output tsv)
    Windows
    $subscriptionId = az account show --query id --output tsv
  • Make table output the defaultLinux, macOS, Windows
    az config set core.output=table
  • Set a default resource groupLinux, macOS, Windows
    az config set defaults.group=my-rg
  • Set a default regionLinux, macOS, Windows
    az config set defaults.location=westeurope
  • Clear the default resource groupLinux, macOS, Windows
    az config unset defaults.group
  • Hide warnings and only show errorsLinux, macOS, Windows
    az vm list --only-show-errors
  • Start a long job and return straight awayLinux, macOS, Windows
    az vm start --name web-1 --resource-group my-rg --no-wait

Resource groups and resources #

  • List resource groupsLinux, macOS, Windows
    az group list --output table
  • Make a resource groupLinux, macOS, Windows
    az group create --name my-rg --location westeurope
  • Check whether a resource group existsLinux, macOS, Windows
    az group exists --name my-rg
  • Show a resource groupLinux, macOS, Windows
    az group show --name my-rg
  • Delete a resource group and everything in itLinux, macOS, Windows
    az group delete --name my-rg --yes --no-wait

    Warning: Deletes every resource in the group, with no undo, and --yes skips the prompt.

  • List the resources in a groupLinux, macOS, Windows
    az resource list --resource-group my-rg --output table
  • List every resource of one typeLinux, macOS, Windows
    az resource list --resource-type Microsoft.Compute/virtualMachines --output table
  • List resources with a tagLinux, macOS, Windows
    az resource list --tag Environment=prod --output table
  • Show a resource by its IDLinux, macOS, Windows
    az resource show --ids /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-rg/providers/Microsoft.Compute/virtualMachines/web-1
  • Delete a resource by its IDLinux, macOS, Windows
    az resource delete --ids /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-rg/providers/Microsoft.Compute/virtualMachines/web-1

    Warning: Deletes the resource with no undo.

  • Add a tag to a resource group, keeping its other tagsLinux, macOS, Windows
    az group update --name my-rg --set tags.Environment=prod
  • Add tags to a resource, keeping its other tagsLinux, macOS, Windows
    az tag update --resource-id /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-rg/providers/Microsoft.Compute/virtualMachines/web-1 --operation Merge --tags Environment=prod
  • Stop a resource group being deletedLinux, macOS, Windows
    az lock create --name no-delete --resource-group my-rg --lock-type CanNotDelete
  • List locksLinux, macOS, Windows
    az lock list --output table
  • Remove a lockLinux, macOS, Windows
    az lock delete --name no-delete --resource-group my-rg
  • Export a resource group as an ARM templateLinux, macOS, Windows
    az group export --name my-rg > template.json
  • Move resources to another resource groupLinux, macOS, Windows
    az resource move --ids /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-rg/providers/Microsoft.Compute/virtualMachines/web-1 --destination-group my-other-rg
  • List resource providers and whether they're registeredLinux, macOS, Windows
    az provider list --query "[].{Provider:namespace, State:registrationState}" --output table
  • Register a resource providerLinux, macOS, Windows
    az provider register --namespace Microsoft.ContainerService

Virtual machines #

  • List VMs with their power state and IP addressesLinux, macOS, Windows
    az vm list --show-details --query "[].{Name:name, Group:resourceGroup, State:powerState, PublicIP:publicIps, PrivateIP:privateIps}" --output table
  • Show everything about one VMLinux, macOS, Windows
    az vm show --name web-1 --resource-group my-rg --show-details
  • Show a VM's public IP addressLinux, macOS, Windows
    az vm show --name web-1 --resource-group my-rg --show-details --query publicIps --output tsv
  • Make a Linux VM with an SSH keyLinux, macOS, Windows
    az vm create --name web-1 --resource-group my-rg --image Ubuntu2404 --size Standard_B2s --admin-username azureuser --generate-ssh-keys
  • Make a Linux VM with no public IP addressLinux, macOS, Windows
    az vm create --name web-1 --resource-group my-rg --image Ubuntu2404 --admin-username azureuser --generate-ssh-keys --public-ip-address "" --nsg ""
  • Make a Windows VMLinux, macOS, Windows
    az vm create --name web-1 --resource-group my-rg --image Win2022Datacenter --size Standard_B2s --admin-username azureuser --admin-password MyPassword

    Warning: The password ends up in your shell history. Leave out --admin-password to be asked for it.

  • Make a VM with a start-up script (cloud-init)Linux, macOS, Windows
    az vm create --name web-1 --resource-group my-rg --image Ubuntu2404 --admin-username azureuser --generate-ssh-keys --custom-data cloud-init.yaml
  • Start a VMLinux, macOS, Windows
    az vm start --name web-1 --resource-group my-rg
  • Stop a VM and stop paying for its computeLinux, macOS, Windows
    az vm deallocate --name web-1 --resource-group my-rg
  • Shut down a VM but keep it allocatedLinux, macOS, Windows
    az vm stop --name web-1 --resource-group my-rg

    Warning: A stopped VM is still billed for compute. Use az vm deallocate to stop paying.

  • Restart a VMLinux, macOS, Windows
    az vm restart --name web-1 --resource-group my-rg
  • Delete a VMLinux, macOS, Windows
    az vm delete --name web-1 --resource-group my-rg --yes

    Warning: Deletes the VM with no undo. Its disks, NIC and public IP are kept unless they were set to delete with it, and you keep paying for them.

  • List the sizes you can resize a VM toLinux, macOS, Windows
    az vm list-vm-resize-options --name web-1 --resource-group my-rg --output table
  • Resize a VMLinux, macOS, Windows
    az vm resize --name web-1 --resource-group my-rg --size Standard_D2s_v5

    Warning: Restarts the VM.

  • List the VM sizes in a regionLinux, macOS, Windows
    az vm list-sizes --location westeurope --output table
  • List popular VM imagesLinux, macOS, Windows
    az vm image list --output table
  • Find images from a publisherLinux, macOS, Windows
    az vm image list --publisher Canonical --offer ubuntu-24_04-lts --all --output table
  • Open a port on a VMLinux, macOS, Windows
    az vm open-port --name web-1 --resource-group my-rg --port 443 --priority 1010
  • Run a shell script on a Linux VM, without SSHLinux, macOS, Windows
    az vm run-command invoke --name web-1 --resource-group my-rg --command-id RunShellScript --scripts "uptime"
  • Run a PowerShell script on a Windows VM, without RDPLinux, macOS, Windows
    az vm run-command invoke --name web-1 --resource-group my-rg --command-id RunPowerShellScript --scripts "Get-Service"
  • Reset a Linux VM's SSH keyLinux, macOS, Windows
    az vm user update --name web-1 --resource-group my-rg --username azureuser --ssh-key-value ~/.ssh/id_ed25519.pub
  • Reset a VM's admin passwordLinux, macOS, Windows
    az vm user update --name web-1 --resource-group my-rg --username azureuser --password MyPassword

    Warning: The password ends up in your shell history.

  • SSH in with your Entra ID account (ssh extension)Linux, macOS, Windows
    az ssh vm --name web-1 --resource-group my-rg
  • Show a VM's boot log, to debug a bootLinux, macOS, Windows
    az vm boot-diagnostics get-boot-log --name web-1 --resource-group my-rg
  • Turn on boot diagnosticsLinux, macOS, Windows
    az vm boot-diagnostics enable --name web-1 --resource-group my-rg
  • Give a VM a managed identityLinux, macOS, Windows
    az vm identity assign --name web-1 --resource-group my-rg
  • List VM extensionsLinux, macOS, Windows
    az vm extension list --vm-name web-1 --resource-group my-rg --output table
  • Wait until a VM is runningLinux, macOS, Windows
    az vm wait --name web-1 --resource-group my-rg --custom "instanceView.statuses[?code=='PowerState/running']"
  • Schedule a VM to shut down every eveningLinux, macOS, Windows
    az vm auto-shutdown --name web-1 --resource-group my-rg --time 1900

Disks and snapshots #

  • List the disks in a resource groupLinux, macOS, Windows
    az disk list --resource-group my-rg --query "[].{Name:name, Group:resourceGroup, SizeGB:diskSizeGB, State:diskState}" --output table
  • List disks that aren't attached to anythingLinux, macOS, Windows
    az disk list --resource-group my-rg --query "[?diskState=='Unattached'].{Name:name, Group:resourceGroup, SizeGB:diskSizeGB}" --output table
  • Make and attach a new data diskLinux, macOS, Windows
    az vm disk attach --vm-name web-1 --resource-group my-rg --name web-1-data --new --size-gb 128
  • Attach an existing diskLinux, macOS, Windows
    az vm disk attach --vm-name web-1 --resource-group my-rg --name web-1-data
  • Detach a diskLinux, macOS, Windows
    az vm disk detach --vm-name web-1 --resource-group my-rg --name web-1-data
  • Make a disk bigger (deallocate the VM first)Linux, macOS, Windows
    az disk update --name web-1-data --resource-group my-rg --size-gb 128
  • Take a snapshot of a diskLinux, macOS, Windows
    az snapshot create --name web-1-data-snap --resource-group my-rg --source web-1-data
  • List snapshotsLinux, macOS, Windows
    az snapshot list --output table
  • Make a disk from a snapshotLinux, macOS, Windows
    az disk create --name web-1-data --resource-group my-rg --source web-1-data-snap
  • Delete a diskLinux, macOS, Windows
    az disk delete --name web-1-data --resource-group my-rg --yes

    Warning: The data is gone for good unless you have a snapshot.

  • Delete a snapshotLinux, macOS, Windows
    az snapshot delete --name web-1-data-snap --resource-group my-rg

    Warning: Deleted snapshots can't be got back.

Networking #

  • List virtual networksLinux, macOS, Windows
    az network vnet list --output table
  • Make a virtual network with a subnetLinux, macOS, Windows
    az network vnet create --name my-vnet --resource-group my-rg --address-prefixes 10.0.0.0/16 --subnet-name web --subnet-prefixes 10.0.1.0/24
  • List a virtual network's subnetsLinux, macOS, Windows
    az network vnet subnet list --vnet-name my-vnet --resource-group my-rg --output table
  • Add a subnetLinux, macOS, Windows
    az network vnet subnet create --name web --vnet-name my-vnet --resource-group my-rg --address-prefixes 10.0.1.0/24
  • Peer two virtual networksLinux, macOS, Windows
    az network vnet peering create --name my-vnet-to-hub --vnet-name my-vnet --resource-group my-rg --remote-vnet /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/hub-rg/providers/Microsoft.Network/virtualNetworks/hub-vnet --allow-vnet-access
  • List network security groupsLinux, macOS, Windows
    az network nsg list --output table
  • Make a network security groupLinux, macOS, Windows
    az network nsg create --name web-nsg --resource-group my-rg
  • List a network security group's rulesLinux, macOS, Windows
    az network nsg rule list --nsg-name web-nsg --resource-group my-rg --output table
  • Allow a port in from one addressLinux, macOS, Windows
    az network nsg rule create --nsg-name web-nsg --resource-group my-rg --name AllowHTTPS --priority 1010 --direction Inbound --access Allow --protocol Tcp --destination-port-ranges 443 --source-address-prefixes 203.0.113.10/32
  • Delete a ruleLinux, macOS, Windows
    az network nsg rule delete --nsg-name web-nsg --resource-group my-rg --name AllowHTTPS
  • Attach a network security group to a subnetLinux, macOS, Windows
    az network vnet subnet update --name web --vnet-name my-vnet --resource-group my-rg --network-security-group web-nsg
  • Allow SSH from your own public IP addressLinux, macOS
    az network nsg rule create --nsg-name web-nsg --resource-group my-rg --name AllowMySSH --priority 100 --destination-port-ranges 22 --source-address-prefixes "$(curl -s https://api.ipify.org)/32"
  • Show the rules that actually apply to a NICLinux, macOS, Windows
    az network nic list-effective-nsg --name web-1VMNic --resource-group my-rg
  • Show the routes that actually apply to a NICLinux, macOS, Windows
    az network nic show-effective-route-table --name web-1VMNic --resource-group my-rg --output table
  • List public IP addressesLinux, macOS, Windows
    az network public-ip list --query "[].{Name:name, IP:ipAddress, AttachedTo:ipConfiguration.id}" --output table
  • Make a static public IP addressLinux, macOS, Windows
    az network public-ip create --name web-1-ip --resource-group my-rg --sku Standard --allocation-method Static
  • Delete a public IP addressLinux, macOS, Windows
    az network public-ip delete --name web-1-ip --resource-group my-rg

    Warning: The address goes back to Azure and you can't get the same one back.

  • List network interfacesLinux, macOS, Windows
    az network nic list --output table
  • Make a route table with a routeLinux, macOS, Windows
    az network route-table create --name spoke-routes --resource-group my-rg az network route-table route create --route-table-name spoke-routes --resource-group my-rg --name to-firewall --address-prefix 203.0.113.10/32 --next-hop-type VirtualAppliance --next-hop-ip-address 10.0.0.4
  • Test whether traffic would be allowed to a VMLinux, macOS, Windows
    az network watcher test-ip-flow --vm web-1 --resource-group my-rg --direction Inbound --protocol TCP --local 10.0.1.4:22 --remote 203.0.113.10:60000
  • List DNS zonesLinux, macOS, Windows
    az network dns zone list --output table
  • List the records in a DNS zoneLinux, macOS, Windows
    az network dns record-set list --zone-name example.com --resource-group my-rg --output table
  • Add an A recordLinux, macOS, Windows
    az network dns record-set a add-record --zone-name example.com --resource-group my-rg --record-set-name www --ipv4-address 203.0.113.10
  • Add a CNAME recordLinux, macOS, Windows
    az network dns record-set cname set-record --zone-name example.com --resource-group my-rg --record-set-name www --cname my-app.azurewebsites.net
  • List private DNS zonesLinux, macOS, Windows
    az network private-dns zone list --output table
  • List private endpointsLinux, macOS, Windows
    az network private-endpoint list --output table

Storage #

  • List storage accountsLinux, macOS, Windows
    az storage account list --query "[].{Name:name, Group:resourceGroup, Kind:kind, Sku:sku.name}" --output table
  • Make a storage accountLinux, macOS, Windows
    az storage account create --name mystorageacct01 --resource-group my-rg --location westeurope --sku Standard_LRS --kind StorageV2 --min-tls-version TLS1_2 --allow-blob-public-access false
  • Check whether a storage account name is freeLinux, macOS, Windows
    az storage account check-name --name mystorageacct01
  • Turn off public blob access on an accountLinux, macOS, Windows
    az storage account update --name mystorageacct01 --resource-group my-rg --allow-blob-public-access false
  • Show a storage account's keysLinux, macOS, Windows
    az storage account keys list --account-name mystorageacct01 --resource-group my-rg --output table

    Warning: Prints a secret in plain text. Don't paste the output anywhere it could be saved or shared.

  • Show a storage account's connection stringLinux, macOS, Windows
    az storage account show-connection-string --name mystorageacct01 --resource-group my-rg --output tsv

    Warning: Prints a secret in plain text. Don't paste the output anywhere it could be saved or shared.

  • Make a new key for a storage accountLinux, macOS, Windows
    az storage account keys renew --account-name mystorageacct01 --resource-group my-rg --key primary

    Warning: Anything still using the old key stops working straight away.

  • Make a blob container, signed in as yourselfLinux, macOS, Windows
    az storage container create --name reports --account-name mystorageacct01 --auth-mode login
  • List blob containersLinux, macOS, Windows
    az storage container list --account-name mystorageacct01 --auth-mode login --output table
  • List the files in a containerLinux, macOS, Windows
    az storage blob list --container-name reports --account-name mystorageacct01 --auth-mode login --query "[].{Name:name, Size:properties.contentLength}" --output table
  • Upload a fileLinux, macOS, Windows
    az storage blob upload --container-name reports --account-name mystorageacct01 --auth-mode login --file report.csv --name 2026/report.csv
  • Upload a file, replacing one that's thereLinux, macOS, Windows
    az storage blob upload --container-name reports --account-name mystorageacct01 --auth-mode login --file report.csv --name 2026/report.csv --overwrite
  • Download a fileLinux, macOS, Windows
    az storage blob download --container-name reports --account-name mystorageacct01 --auth-mode login --name 2026/report.csv --file report.csv
  • Upload a folderLinux, macOS, Windows
    az storage blob upload-batch --destination reports --account-name mystorageacct01 --auth-mode login --source ./site
  • Download a whole containerLinux, macOS, Windows
    az storage blob download-batch --source reports --account-name mystorageacct01 --auth-mode login --destination ./site
  • Delete a fileLinux, macOS, Windows
    az storage blob delete --container-name reports --account-name mystorageacct01 --auth-mode login --name 2026/report.csv

    Warning: Deleted files can't be got back unless soft delete is on.

  • Delete every file that matches a patternLinux, macOS, Windows
    az storage blob delete-batch --source reports --account-name mystorageacct01 --auth-mode login --pattern "logs/*.log"

    Warning: Deletes every match. Run it with --dryrun first.

  • Copy a file between accountsLinux, macOS, Windows
    az storage blob copy start --destination-container reports --destination-blob 2026/report.csv --account-name mystorageacct01 --auth-mode login --source-uri https://otheracct.blob.core.windows.net/reports/2026/report.csv
  • Make a read-only link to a file that expiresLinux, macOS, Windows
    az storage blob generate-sas --container-name reports --account-name mystorageacct01 --name 2026/report.csv --permissions r --expiry 2026-12-31T23:59Z --auth-mode login --as-user --full-uri

    Warning: Anyone with the link can download the file until it expires.

  • Turn on soft delete for blobsLinux, macOS, Windows
    az storage account blob-service-properties update --account-name mystorageacct01 --resource-group my-rg --enable-delete-retention true --delete-retention-days 14
  • Turn on static website hostingLinux, macOS, Windows
    az storage blob service-properties update --account-name mystorageacct01 --auth-mode login --static-website --index-document index.html --404-document 404.html
  • Make a file shareLinux, macOS, Windows
    az storage share-rm create --name files --storage-account mystorageacct01 --resource-group my-rg --quota 128

Entra ID and access control #

  • Show who you're signed in asLinux, macOS, Windows
    az ad signed-in-user show --query "{Name:displayName, UPN:userPrincipalName, Id:id}"
  • Find a userLinux, macOS, Windows
    az ad user list --filter "startswith(displayName, 'Alice')" --query "[].{Name:displayName, UPN:userPrincipalName}" --output table
  • Show a userLinux, macOS, Windows
    az ad user show --id [email protected]
  • List a user's groupsLinux, macOS, Windows
    az ad user get-member-groups --id [email protected]
  • List groupsLinux, macOS, Windows
    az ad group list --query "[].{Name:displayName, Id:id}" --output table
  • List a group's membersLinux, macOS, Windows
    az ad group member list --group "Cloud Admins" --query "[].userPrincipalName" --output tsv
  • Add a user to a groupLinux, macOS, Windows
    az ad group member add --group "Cloud Admins" --member-id 00000000-0000-0000-0000-000000000000
  • List app registrationsLinux, macOS, Windows
    az ad app list --show-mine --query "[].{Name:displayName, AppId:appId}" --output table
  • Find a service principalLinux, macOS, Windows
    az ad sp list --display-name github-deploy --query "[].{Name:displayName, AppId:appId}" --output table
  • Make a service principal with a role on a resource groupLinux, macOS, Windows
    az ad sp create-for-rbac --name github-deploy --role Contributor --scopes /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-rg

    Warning: The output includes a client secret in plain text. Store it somewhere safe.

  • Give a service principal a new secretLinux, macOS, Windows
    az ad sp credential reset --id 00000000-0000-0000-0000-000000000000

    Warning: Replaces the existing secret, so anything using it stops working. The new one is printed in plain text.

  • List role assignments in a resource groupLinux, macOS, Windows
    az role assignment list --resource-group my-rg --output table
  • List everything someone has access toLinux, macOS, Windows
    az role assignment list --assignee [email protected] --all --output table
  • Give someone a role on a resource groupLinux, macOS, Windows
    az role assignment create --assignee [email protected] --role "Reader" --scope /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-rg
  • Remove someone's roleLinux, macOS, Windows
    az role assignment delete --assignee [email protected] --role "Reader" --resource-group my-rg
  • List the built-in rolesLinux, macOS, Windows
    az role definition list --query "[?roleType=='BuiltInRole'].roleName" --output tsv
  • Show what a role allowsLinux, macOS, Windows
    az role definition list --name "Reader"
  • Show a managed identity's IDsLinux, macOS, Windows
    az identity show --name my-identity --resource-group my-rg --query "{ClientId:clientId, PrincipalId:principalId}"

Key Vault #

  • List key vaultsLinux, macOS, Windows
    az keyvault list --output table
  • Make a key vault that uses Azure roles for accessLinux, macOS, Windows
    az keyvault create --name my-vault --resource-group my-rg --location westeurope --enable-rbac-authorization true
  • List the secrets in a vaultLinux, macOS, Windows
    az keyvault secret list --vault-name my-vault --query "[].name" --output tsv
  • Read a secretLinux, macOS, Windows
    az keyvault secret show --vault-name my-vault --name db-password --query value --output tsv

    Warning: Prints a secret in plain text. Don't paste the output anywhere it could be saved or shared.

  • Save a secret from a fileLinux, macOS, Windows
    az keyvault secret set --vault-name my-vault --name db-password --file report.csv
  • Save a secretLinux, macOS, Windows
    az keyvault secret set --vault-name my-vault --name db-password --value "MyPassword"

    Warning: The value ends up in your shell history. Use --file to avoid that.

  • Delete a secretLinux, macOS, Windows
    az keyvault secret delete --vault-name my-vault --name db-password
  • List deleted secrets you can still get backLinux, macOS, Windows
    az keyvault secret list-deleted --vault-name my-vault --output table
  • Get a deleted secret backLinux, macOS, Windows
    az keyvault secret recover --vault-name my-vault --name db-password
  • Make a keyLinux, macOS, Windows
    az keyvault key create --vault-name my-vault --name my-key --kty RSA --size 3072
  • List certificates in a vaultLinux, macOS, Windows
    az keyvault certificate list --vault-name my-vault --output table
  • List deleted vaults you can still get backLinux, macOS, Windows
    az keyvault list-deleted --output table
  • Get a deleted vault backLinux, macOS, Windows
    az keyvault recover --name my-vault

App Service and Functions #

  • List web appsLinux, macOS, Windows
    az webapp list --query "[].{Name:name, Group:resourceGroup, State:state, Host:defaultHostName}" --output table
  • List the runtimes you can useLinux, macOS, Windows
    az webapp list-runtimes --os linux --output table
  • Make an App Service planLinux, macOS, Windows
    az appservice plan create --name my-plan --resource-group my-rg --sku B1 --is-linux
  • Make a web app in a planLinux, macOS, Windows
    az webapp create --name my-webapp --resource-group my-rg --plan my-plan --runtime "NODE:22-lts"
  • Deploy a zip file to a web appLinux, macOS, Windows
    az webapp deploy --name my-webapp --resource-group my-rg --src-path app.zip --type zip
  • Follow a web app's logs liveLinux, macOS, Windows
    az webapp log tail --name my-webapp --resource-group my-rg
  • Turn on application loggingLinux, macOS, Windows
    az webapp log config --name my-webapp --resource-group my-rg --application-logging filesystem --level information
  • Restart a web appLinux, macOS, Windows
    az webapp restart --name my-webapp --resource-group my-rg
  • Stop a web appLinux, macOS, Windows
    az webapp stop --name my-webapp --resource-group my-rg
  • List a web app's settingsLinux, macOS, Windows
    az webapp config appsettings list --name my-webapp --resource-group my-rg --output table

    Warning: Settings often hold secrets, and they're shown in plain text.

  • Change a web app settingLinux, macOS, Windows
    az webapp config appsettings set --name my-webapp --resource-group my-rg --settings LOG_LEVEL=debug
  • Only allow HTTPS to a web appLinux, macOS, Windows
    az webapp update --name my-webapp --resource-group my-rg --https-only true
  • List deployment slotsLinux, macOS, Windows
    az webapp deployment slot list --name my-webapp --resource-group my-rg --output table
  • Swap a staging slot into productionLinux, macOS, Windows
    az webapp deployment slot swap --name my-webapp --resource-group my-rg --slot staging --target-slot production
  • Add a custom domain to a web appLinux, macOS, Windows
    az webapp config hostname add --webapp-name my-webapp --resource-group my-rg --hostname SW1
  • List function appsLinux, macOS, Windows
    az functionapp list --query "[].{Name:name, Group:resourceGroup, State:state}" --output table
  • Make a function app on the Flex Consumption planLinux, macOS, Windows
    az functionapp create --name my-func --resource-group my-rg --storage-account mystorageacct01 --flexconsumption-location westeurope --runtime python --runtime-version 3.12
  • Deploy a zip file to a function appLinux, macOS, Windows
    az functionapp deployment source config-zip --name my-func --resource-group my-rg --src app.zip
  • List the functions in an appLinux, macOS, Windows
    az functionapp function list --name my-func --resource-group my-rg --output table
  • Change a function app settingLinux, macOS, Windows
    az functionapp config appsettings set --name my-func --resource-group my-rg --settings LOG_LEVEL=debug

Containers: ACR, AKS, ACI and Container Apps #

  • List container registriesLinux, macOS, Windows
    az acr list --output table
  • Make a container registryLinux, macOS, Windows
    az acr create --name myregistry --resource-group my-rg --sku Basic
  • Sign Docker in to a registryLinux, macOS, Windows
    az acr login --name myregistry
  • Build an image in Azure and push it, no Docker neededLinux, macOS, Windows
    az acr build --registry myregistry --image my-app:v1 .
  • List the repositories in a registryLinux, macOS, Windows
    az acr repository list --name myregistry --output table
  • List an image's tags, newest firstLinux, macOS, Windows
    az acr repository show-tags --name myregistry --repository my-app --orderby time_desc --output table
  • Delete an image tagLinux, macOS, Windows
    az acr repository delete --name myregistry --image my-app:v1 --yes

    Warning: Deletes the image with no undo.

  • List AKS clustersLinux, macOS, Windows
    az aks list --query "[].{Name:name, Group:resourceGroup, Version:kubernetesVersion, State:powerState.code}" --output table
  • Set up kubectl for an AKS clusterLinux, macOS, Windows
    az aks get-credentials --name my-aks --resource-group my-rg
  • Install kubectl and kubeloginLinux, macOS, Windows
    az aks install-cli
  • Make an AKS clusterLinux, macOS, Windows
    az aks create --name my-aks --resource-group my-rg --node-count 2 --generate-ssh-keys --enable-managed-identity
  • Let an AKS cluster pull from a registryLinux, macOS, Windows
    az aks update --name my-aks --resource-group my-rg --attach-acr myregistry
  • Scale an AKS node poolLinux, macOS, Windows
    az aks scale --name my-aks --resource-group my-rg --nodepool-name nodepool1 --node-count 3
  • List an AKS cluster's node poolsLinux, macOS, Windows
    az aks nodepool list --cluster-name my-aks --resource-group my-rg --output table
  • Show the versions an AKS cluster can upgrade toLinux, macOS, Windows
    az aks get-upgrades --name my-aks --resource-group my-rg --output table
  • Upgrade an AKS clusterLinux, macOS, Windows
    az aks upgrade --name my-aks --resource-group my-rg --kubernetes-version 1.33.2

    Warning: Nodes are drained and replaced one by one. You can't go back to an older version.

  • Stop an AKS cluster to save moneyLinux, macOS, Windows
    az aks stop --name my-aks --resource-group my-rg
  • Start an AKS clusterLinux, macOS, Windows
    az aks start --name my-aks --resource-group my-rg
  • Run a kubectl command on a private AKS clusterLinux, macOS, Windows
    az aks command invoke --name my-aks --resource-group my-rg --command "kubectl get pods -A"
  • Run a container instanceLinux, macOS, Windows
    az container create --name my-aci --resource-group my-rg --image nginx:latest --os-type Linux --cpu 1 --memory 1.5 --ports 80 --ip-address Public
  • Show a container instance's logsLinux, macOS, Windows
    az container logs --name my-aci --resource-group my-rg
  • Open a shell in a container instanceLinux, macOS, Windows
    az container exec --name my-aci --resource-group my-rg --exec-command "/bin/sh"
  • List container appsLinux, macOS, Windows
    az containerapp list --output table
  • Update a container app to a new imageLinux, macOS, Windows
    az containerapp update --name my-containerapp --resource-group my-rg --image myregistry.azurecr.io/my-app:v1
  • Follow a container app's logsLinux, macOS, Windows
    az containerapp logs show --name my-containerapp --resource-group my-rg --follow
  • Open a shell in a container appLinux, macOS, Windows
    az containerapp exec --name my-containerapp --resource-group my-rg --command "/bin/sh"

Databases #

  • List Azure SQL serversLinux, macOS, Windows
    az sql server list --output table
  • List the databases on a SQL serverLinux, macOS, Windows
    az sql db list --server my-sqlserver --resource-group my-rg --output table
  • Let your IP address through a SQL server's firewallLinux, macOS, Windows
    az sql server firewall-rule create --server my-sqlserver --resource-group my-rg --name AllowHTTPS --start-ip-address 203.0.113.10 --end-ip-address 203.0.113.10
  • Show a SQL database's connection stringLinux, macOS, Windows
    az sql db show-connection-string --server my-sqlserver --name appdb --client ado.net
  • List PostgreSQL flexible serversLinux, macOS, Windows
    az postgres flexible-server list --output table
  • Let your IP address through a PostgreSQL server's firewallLinux, macOS, Windows
    az postgres flexible-server firewall-rule create --server-name my-postgres --resource-group my-rg --name AllowHTTPS --start-ip-address 203.0.113.10
  • Stop a PostgreSQL flexible serverLinux, macOS, Windows
    az postgres flexible-server stop --name my-postgres --resource-group my-rg

    Warning: Azure starts a stopped server again by itself after 7 days.

  • Start a PostgreSQL flexible serverLinux, macOS, Windows
    az postgres flexible-server start --name my-postgres --resource-group my-rg
  • List MySQL flexible serversLinux, macOS, Windows
    az mysql flexible-server list --output table
  • List Cosmos DB accountsLinux, macOS, Windows
    az cosmosdb list --query "[].{Name:name, Group:resourceGroup, Kind:kind}" --output table
  • List Redis cachesLinux, macOS, Windows
    az redis list --output table

Monitoring and logs #

  • Show the last day of changes in a resource groupLinux, macOS, Windows
    az monitor activity-log list --resource-group my-rg --offset 1d --query "[].{Time:eventTimestamp, Who:caller, What:operationName.localizedValue, Status:status.value}" --output table
  • Find who deleted somethingLinux, macOS, Windows
    az monitor activity-log list --offset 7d --query "[?contains(operationName.value, 'delete')].{Time:eventTimestamp, Who:caller, Resource:resourceId}" --output table
  • List the metrics a resource hasLinux, macOS, Windows
    az monitor metrics list-definitions --resource /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-rg/providers/Microsoft.Compute/virtualMachines/web-1 --query "[].name.value" --output tsv
  • Show a VM's CPU over the last hourLinux, macOS, Windows
    az monitor metrics list --resource /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-rg/providers/Microsoft.Compute/virtualMachines/web-1 --metric "Percentage CPU" --interval PT5M --offset 1h --output table
  • List metric alertsLinux, macOS, Windows
    az monitor metrics alert list --output table
  • Make an alert for high CPULinux, macOS, Windows
    az monitor metrics alert create --name web-1-high-cpu --resource-group my-rg --scopes /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-rg/providers/Microsoft.Compute/virtualMachines/web-1 --condition "avg Percentage CPU > 80" --window-size 5m --evaluation-frequency 1m --action ops-team
  • List action groupsLinux, macOS, Windows
    az monitor action-group list --output table
  • List Log Analytics workspacesLinux, macOS, Windows
    az monitor log-analytics workspace list --output table
  • Run a KQL query on a Log Analytics workspace (log-analytics extension)Linux, macOS, Windows
    az monitor log-analytics query --workspace 00000000-0000-0000-0000-000000000000 --analytics-query "Heartbeat | summarize count() by Computer" --output table
  • List a resource's diagnostic settingsLinux, macOS, Windows
    az monitor diagnostic-settings list --resource /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-rg/providers/Microsoft.Compute/virtualMachines/web-1
  • Show Azure Advisor recommendationsLinux, macOS, Windows
    az advisor recommendation list --query "[].{Category:category, Impact:impact, Problem:shortDescription.problem}" --output table

Deployments: ARM and Bicep #

  • Install or update BicepLinux, macOS, Windows
    az bicep install
  • Show the Bicep versionLinux, macOS, Windows
    az bicep version
  • Check a Bicep file for mistakes and build it to ARM JSONLinux, macOS, Windows
    az bicep build --file main.bicep
  • Turn an ARM template into BicepLinux, macOS, Windows
    az bicep decompile --file template.json
  • Check a deployment would work, without deployingLinux, macOS, Windows
    az deployment group validate --resource-group my-rg --template-file main.bicep
  • See what a deployment would changeLinux, macOS, Windows
    az deployment group what-if --resource-group my-rg --template-file main.bicep
  • Deploy a Bicep or ARM file to a resource groupLinux, macOS, Windows
    az deployment group create --resource-group my-rg --template-file main.bicep
  • Deploy with a parameters fileLinux, macOS, Windows
    az deployment group create --resource-group my-rg --template-file main.bicep --parameters main.bicepparam
  • Deploy and set one parameterLinux, macOS, Windows
    az deployment group create --resource-group my-rg --template-file main.bicep --parameters environment=prod
  • Deploy to a subscription, to make resource groups or policiesLinux, macOS, Windows
    az deployment sub create --location westeurope --template-file main.bicep
  • List deployments in a resource groupLinux, macOS, Windows
    az deployment group list --resource-group my-rg --query "[].{Name:name, State:properties.provisioningState, Time:properties.timestamp}" --output table
  • Show what went wrong in a deploymentLinux, macOS, Windows
    az deployment operation group list --resource-group my-rg --name main --query "[?properties.provisioningState=='Failed'].properties.statusMessage"
  • Show a deployment's outputsLinux, macOS, Windows
    az deployment group show --resource-group my-rg --name main --query properties.outputs
  • Deploy a deployment stack that deletes resources you remove from the fileLinux, macOS, Windows
    az stack group create --name main --resource-group my-rg --template-file main.bicep --action-on-unmanage deleteResources --deny-settings-mode none

    Warning: Resources you take out of the file are deleted on the next deploy.

Policy, cost and Resource Graph #

  • List policy assignmentsLinux, macOS, Windows
    az policy assignment list --query "[].{Name:displayName, Scope:scope}" --output table
  • Show how many resources break each policyLinux, macOS, Windows
    az policy state summarize --query "policyAssignments[].{Policy:policyAssignmentId, NonCompliant:results.nonCompliantResources}"
  • List resources that break policyLinux, macOS, Windows
    az policy state list --filter "complianceState eq 'NonCompliant'" --query "[].{Resource:resourceId, Policy:policyDefinitionName}" --output table
  • Assign a built-in policy to a resource groupLinux, macOS, Windows
    az policy assignment create --name require-tags --policy 871b6d14-10aa-478d-b590-94f262ecfa99 --scope /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-rg
  • Show your spend on each resource between two datesLinux, macOS, Windows
    az consumption usage list --start-date 2026-11-01 --end-date 2026-11-30 --query "[].{Resource:instanceName, Cost:pretaxCost, Currency:currency}" --output table
  • List your budgetsLinux, macOS, Windows
    az consumption budget list --output table
  • Make a monthly budgetLinux, macOS, Windows
    az consumption budget create --budget-name monthly --amount 100 --category cost --time-grain monthly --start-date 2026-11-01 --end-date 2027-11-01
  • Search every resource you can see with KQL (resource-graph extension)Linux, macOS, Windows
    az graph query --graph-query "Resources | summarize count() by type | order by count_ desc" --output table
  • Find unattached disks across every subscription (resource-graph extension)Linux, macOS, Windows
    az graph query --graph-query "Resources | where type =~ 'microsoft.compute/disks' and properties.diskState == 'Unattached' | project name, resourceGroup, sku.name" --output table
  • Find VMs across every subscription (resource-graph extension)Linux, macOS, Windows
    az graph query --graph-query "Resources | where type =~ 'microsoft.compute/virtualmachines' | project name, resourceGroup, location" --output table

Troubleshooting #

  • Show every request and response, to debug a commandLinux, macOS, Windows
    az vm list --debug

    Warning: The debug output includes your access token. Check it before you share it.

  • Show more detail about what a command is doingLinux, macOS, Windows
    az vm list --verbose
  • Call any Azure REST API directlyLinux, macOS, Windows
    az rest --method get --url "https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups?api-version=2021-04-01"
  • Call Microsoft Graph directlyLinux, macOS, Windows
    az rest --method get --url "https://graph.microsoft.com/v1.0/me"
  • Clear the CLI's cache of resourcesLinux, macOS, Windows
    az cache purge
  • Fix sign-in problems by signing in again from scratchLinux, macOS, Windows
    az account clear az login
  • Turn off the CLI's usage dataLinux, macOS, Windows
    az config set core.collect_telemetry=false
  • Find the CLI's config and log folderLinux, macOS
    echo ~/.azure
  • Send a command through a proxy
    Linux, macOS
    export HTTPS_PROXY=http://proxy.example.com:8080
    Windows
    $env:HTTPS_PROXY = "http://proxy.example.com:8080"