Azure CLI Cheat Sheet: az Commands with Examples
The Azure CLI commands you use most, grouped by job, with a working example for each. Names such as rg1, vm1 and mystorage123 are examples: swap in your own. Bookmark this page or download the free PDF.
Sign in and choose a subscription
| Command | What it does |
|---|---|
az login |
Sign in through a browser |
az login --use-device-code |
Sign in with a code, for a machine with no browser |
az account list --output table |
List your subscriptions |
az account show |
Show the subscription you are using now |
az account set --subscription "My Subscription" |
Switch to another subscription |
az logout |
Sign out |
Remember: Check which subscription is active before you create or delete anything.
Resource groups
| Command | What it does |
|---|---|
az group create --name rg1 --location westeurope |
Create a resource group |
az group list --output table |
List resource groups |
az group show --name rg1 |
Details of one group |
az group exists --name rg1 |
Prints true or false |
az group delete --name rg1 --yes --no-wait |
Delete the group and everything in it, without waiting |
Virtual machines
| Command | What it does |
|---|---|
az vm create --resource-group rg1 --name vm1 --image Ubuntu2204 --admin-username azureuser --generate-ssh-keys |
Create a Linux VM with SSH keys |
az vm list --resource-group rg1 --output table |
List the VMs in a group |
az vm show --resource-group rg1 --name vm1 |
Details of one VM |
az vm stop --resource-group rg1 --name vm1 |
Power off, but you are still billed for the VM |
az vm deallocate --resource-group rg1 --name vm1 |
Power off and release the compute resources (no compute charges) |
az vm start --resource-group rg1 --name vm1 |
Start a VM |
az vm restart --resource-group rg1 --name vm1 |
Restart a VM |
az vm open-port --resource-group rg1 --name vm1 --port 80 |
Open a port to the VM |
az vm list-sizes --location westeurope --output table |
VM sizes available in a region |
az vm delete --resource-group rg1 --name vm1 --yes |
Delete a VM |
Remember: stop keeps charging; deallocate is the one that stops the compute bill.
Storage
| Command | What it does |
|---|---|
az storage account create --name mystorage123 --resource-group rg1 --location westeurope --sku Standard_LRS |
Create a storage account |
az storage account list --output table |
List storage accounts |
az storage container create --account-name mystorage123 --name files --auth-mode login |
Create a blob container, signing in with your Entra ID account |
az storage blob upload --account-name mystorage123 --container-name files --name report.pdf --file report.pdf --auth-mode login |
Upload a file as a blob |
az storage blob list --account-name mystorage123 --container-name files --auth-mode login --output table |
List the blobs in a container |
Networking
| Command | What it does |
|---|---|
az network vnet create --resource-group rg1 --name vnet1 --address-prefixes 10.0.0.0/16 --subnet-name subnet1 --subnet-prefixes 10.0.1.0/24 |
Create a virtual network with a subnet |
az network nsg create --resource-group rg1 --name nsg1 |
Create a network security group |
az network nsg rule create --resource-group rg1 --nsg-name nsg1 --name allow-ssh --priority 100 --access Allow --protocol Tcp --direction Inbound --destination-port-ranges 22 |
Add an inbound rule |
az network public-ip create --resource-group rg1 --name ip1 --sku Standard |
Create a public IP address |
Access, deployments and containers
| Command | What it does |
|---|---|
az role assignment create --assignee user@contoso.com --role Reader --scope /subscriptions/SUB_ID/resourceGroups/rg1 |
Give a user a role on a resource group |
az ad sp create-for-rbac --name myapp --role Contributor --scopes /subscriptions/SUB_ID/resourceGroups/rg1 |
Create a service principal with a role |
az deployment group create --resource-group rg1 --template-file main.bicep |
Deploy a Bicep or ARM template to a group |
az aks create --resource-group rg1 --name aks1 --node-count 2 --generate-ssh-keys |
Create an AKS cluster |
az aks get-credentials --resource-group rg1 --name aks1 |
Add the cluster to your kubeconfig for kubectl |
Output, queries and defaults
| Command | What it does |
|---|---|
az vm list --output table |
Human-friendly table (also json, tsv, yaml) |
az vm list --query "[].name" --output tsv |
Only the VM names, one per line |
az vm list --query "[?location=='westeurope'].name" --output tsv |
Filter with a JMESPath query |
az configure --defaults group=rg1 location=westeurope |
Set a default group and location |
Remember: The --query option uses JMESPath and works on every command.
Help and housekeeping
| Command | What it does |
|---|---|
az vm create --help |
Help for any command |
az find "az storage" |
Search for commands and examples |
az interactive |
Interactive mode with completion |
az version |
Show the CLI version |
az upgrade |
Update the CLI |
Common mistakes
-
az vm stoppowers the VM off but you are still billed for it. Useaz vm deallocateto release the compute resources. - Deleting a resource group deletes everything inside it. Check the name before you add
--yes. - Storage account names must be 3 to 24 characters, lower-case letters and numbers only, and unique across Azure.
-
--queryuses JMESPath, which is case sensitive and quote-sensitive. Quoting differs between Bash and PowerShell. - Blob commands need an account name and a way to sign in, such as
--auth-mode login.
Azure CLI FAQ
How do I switch subscription in the Azure CLI?az account set --subscription "NAME OR ID". Check the result with az account show.
How do I list resources in a table?
Add --output table to the command. Other formats include json, tsv and yaml.
What is the difference between az vm stop and az vm deallocate?stop powers off the VM but it continues to be billed. deallocate also releases the compute resources, so compute charges no longer apply.
How do I filter the output?
Use --query with a JMESPath expression, for example az vm list --query "[].name" --output tsv.
Practise it
Learning Azure administration? Try the free AZ-104 practice test, and read our AZ-104 skills measured guide.
Commands and options follow the Azure CLI reference on learn.microsoft.com (the reference index and the account, group, vm, storage, network, aks, deployment, role and ad sp pages, plus the pages on querying and formatting output), checked on 17 November 2026. Resource names, locations and the subscription ID are examples. Commands change between CLI versions, so run the --help for your version.
Studying for Azure exams? See the Microsoft AZ-104 real exam questions and the Microsoft AZ-400 real exam questions.
What people say about this pack
I passed my exam today and got 90% passing marks in it. Thanks to Daily Debian.
Highly recommended for anyone preparing for the AZ-104 exam. Thanks Daily Debian.