Azure CLI Commands Explained with Examples – Complete Guide (2026)

Over the past few years, Microsoft Azure’s popularity has been steadily increasing due to its fair pricing and free tier options, and so many of us have moved our workloads to Azure. But managing everything through the Azure portal user interface can be slow and complicated, especially with larger projects.

This is where Azure CLI commands come in. Azure CLI allows us to manage Azure resources using the command line. In this guide, my goal is not only to introduce you to different useful Azure CLI commands but also to explain how it works in a simple and practical way with examples.

Authentication and Configuration Azure CLI Commands

We begin our journey by setting up our environment. These Azure CLI commands help us log in and manage our configuration settings so we can connect to our Azure account securely.

az login

This command opens a browser window to let us sign in to our Azure account interactively. It authenticates our session so we can manage resources. We use it when we start a new terminal session. The result is a successful connection to our Azure tenant. Example:

az login

az logout

We use this command to sign out of the current Azure account. It ends the active session and clears the cached access tokens. We run this when we finish our work or switch to a different account. The result is a logged-out state. Example:

az logout

az account list

This command shows all the subscriptions associated with our logged-in account. It displays details like the subscription ID and name. We use it to see which accounts we have access to manage. The result is a list of available subscriptions. Example:

az account list --output table

az account set

We use this command to select a specific subscription as the active one. It takes a subscription ID or name to set the context. We need this when we have multiple subscriptions and want to work on a specific one. The result changes the focus for future commands. Example:

az account set--subscription"My Subscription Name"

az configure

This command allows us to change the default settings for the Azure CLI. We can set defaults for the resource group, location, or output format. We use it to save time so we do not have to type these values repeatedly. The result updates our configuration file. Example:

az configure --defaultsgroup=myResourceGroup location=eastus

Resource Group Azure CLI Commands

Resource groups act as containers for our Azure resources. These Azure CLI commands help us create, manage, and delete these groups to keep our cloud environment organized.

az group create

We use this command to create a new resource group in a specific location. It requires a name and a region. This is the first step when we deploy new infrastructure. The result is a new container ready to hold resources. Example:

az group create --name MyResourceGroup --location eastus

az group list

This command lists all resource groups in our current subscription. It helps us see what we have created. We use it to check the status of our projects or find a specific group name. The result is a list of all existing groups. Example:

az group list --output table

az group show

We use this command to display the details of a specific resource group. It shows the location, provisioning state, and tags. It is useful for verifying the properties of a group. The result shows the full JSON output of that group. Example:

az group show --name MyResourceGroup

az group delete

This command deletes a resource group and all resources inside it. We use this action when we want to clean up a project completely. We must be careful because this action cannot be undone easily. The result is the removal of the group and its contents. Example:

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

az group exists

We use this command to check if a resource group exists in our subscription. It returns a status code or true/false result. We use it in scripts to avoid errors before trying to create or delete a group. The result confirms existence. Example:

az group exists --name MyResourceGroup

Virtual Machine Azure CLI Commands

Virtual machines are a core part of cloud computing. These Azure CLI commands allow us to create, start, stop, and manage our virtual servers efficiently.

az vm create

We use this command to create a new virtual machine in Azure. It requires details like the resource group, name, and image. This is one of the most common commands for setting up a server. The result is a running virtual machine. Example:

az vm create --resource-group MyResourceGroup --name MyVM --image Ubuntu2204

az vm list

This command lists all the virtual machines in our subscription or resource group. We use it to see an overview of our servers. The result displays a list of VM names, locations, and power states. Example:

az vm list --resource-group MyResourceGroup --output table

az vm start

We use this command to start a virtual machine that is currently stopped. It powers up the server so we can use it again. We run this when we want to access our applications or services. The result is a VM in a running state. Example:

az vm start--resource-group MyResourceGroup --name MyVM

az vm stop

This command shuts down a running virtual machine. We use it to stop the server when we are not using it to save money on compute costs. The result is a VM in a stopped state. Example:

az vm stop--resource-group MyResourceGroup --name MyVM

az vm deallocate

We use this command to deallocate the virtual machine from the Azure hardware. This releases the compute resources completely. We use it to ensure we are not billed for the VM allocation. The result is a VM in a stopped and deallocated state. Example:

az vm deallocate --resource-group MyResourceGroup --name MyVM

az vm restart

This command restarts a running virtual machine. We use it to apply updates or fix software issues. It is similar to clicking the restart button on a physical computer. The result is a VM that reboots and comes back online. Example:

az vm restart--resource-group MyResourceGroup --name MyVM

az vm delete

We use this command to permanently delete a virtual machine. It removes the VM resource but might keep attached disks depending on flags. We use it when we no longer need the server. The result is the removal of the VM from Azure. Example:

az vm delete --resource-group MyResourceGroup --name MyVM --yes

az vm open-port

This command creates a network security rule to open a specific port on the VM. We use it to allow traffic like web requests or SSH access. The result allows external communication on that port. Example:

az vm open-port --resource-group MyResourceGroup --name MyVM --port80

az vm show

We use this command to display detailed information about a virtual machine. It shows the size, OS, disks, and network interfaces. We use it to check the configuration or status of a server. The result shows the full details of the VM. Example:

az vm show --resource-group MyResourceGroup --name MyVM

az vm update

We use this command to update properties of a virtual machine. We can change tags, add a managed disk, or modify other settings. We run this when we need to change the VM configuration. The result applies the new settings to the VM. Example:

az vm update --resource-group MyResourceGroup --name MyVM --set tags.environment=Production

Networking Azure CLI Commands

Networking connects our resources to the internet and each other. These Microsoft Azure CLI commands help us manage virtual networks, subnets, and IP addresses.

az network vnet create

We use this command to create a virtual network. It defines the network space where our resources live. We use it to isolate our cloud environment securely. The result is a new virtual network container. Example:

az network vnet create --resource-group MyResourceGroup --name MyVNet --address-prefix10.0.0.0/16

az network subnet create

This command creates a subnet within a virtual network. We use it to divide the network into smaller segments. It helps us organize resources by security or function. The result is a new subnet ready for resources. Example:

az network subnet create --resource-group MyResourceGroup --vnet-name MyVNet --name MySubnet --address-prefix10.0.1.0/24

az network public-ip create

We use this command to create a public IP address. This address lets our resources communicate with the internet. We assign it to load balancers or VMs. The result is a new public IP resource. Example:

az network public-ip create --resource-group MyResourceGroup --name MyPublicIP

az network nic create

This command creates a network interface card (NIC). The NIC connects a virtual machine to a network. We use it when creating a VM to define its network connection. The result is a NIC ready for attachment. Example:

az network nic create --resource-group MyResourceGroup --name MyNIC --vnet-name MyVNet --subnet MySubnet

az network nsg create

We use this command to create a network security group. It acts as a virtual firewall to control traffic. We use it to block or allow specific network flows. The result is a new security group container. Example:

az network nsg create --resource-group MyResourceGroup --name MyNSG

az network nsg rule create

This command adds a security rule to a network security group. We use it to allow or deny traffic on specific ports. It helps us secure our applications and data. The result is a new rule applied to the NSG. Example:

az network nsg rule create --resource-group MyResourceGroup --nsg-name MyNSG --name AllowSSH --protocol tcp --direction inbound --priority1000--source-address-prefix'*'--source-port-range'*'--destination-address-prefix'*'--destination-port-range22--access allow

az network vnet list

We use this command to list all virtual networks in our subscription. It helps us see our network topology. We use it to verify names and address ranges. The result displays a list of all VNet names. Example:

az network vnet list --output table

az network dns zone create

This command creates a DNS zone for hosting our domain records. We use it to manage the DNS for our website or services. The result is a new zone where we can add records. Example:

az network dns zone create --resource-group MyResourceGroup --name mydomain.com

az network dns record-set a add-record

We use this command to add an A record to a DNS zone. It maps a domain name to an IP address. We use it so users can reach our services via a friendly URL. The result adds the record to the zone. Example:

az network dns record-set a add-record --resource-group MyResourceGroup --zone-name mydomain.com --record-set-name www --ipv4-address10.0.0.4

Storage and Database Azure CLI Commands

Storage and databases hold our data securely. These Azure CLI commands help us manage storage accounts, containers, and SQL databases.

az storage account create

We use this command to create a storage account. It provides the namespace for all our storage objects like blobs and files. We use it to store data reliably in the cloud. The result is a new storage account. Example:

az storage account create --name mystorageaccount --resource-group MyResourceGroup --location eastus --sku Standard_LRS

az storage account show

This command shows the details of a specific storage account. We use it to check the keys, status, or SKU type. It is useful for verifying our storage setup. The result displays the account properties. Example:

az storage account show --name mystorageaccount --resource-group MyResourceGroup

az storage account list

We use this command to list all storage accounts in the subscription. It helps us see our storage resources and their locations. The result shows a list of all account names. Example:

az storage account list --output table

az storage container create

This command creates a container within a storage account. We use containers to organize blobs, similar to folders. We use this to store images or documents. The result is a new container. Example:

az storage container create --name mycontainer --account-name mystorageaccount

az storage blob upload

We use this command to upload a file to a blob container. It sends local data to the cloud storage. We use this to back up files or host static assets. The result is the file stored in Azure. Example:

az storage blob upload --account-name mystorageaccount --container-name mycontainer --name myfile.txt --file ./myfile.txt

az storage blob download

We use this command to download a file from Azure storage to our local machine. It retrieves data from the cloud. We use this to get our backups or data back. The result is the file saved locally. Example:

az storage blob download --account-name mystorageaccount --container-name mycontainer --name myfile.txt --file ./myfile.txt

az sql server create

We use this command to create an Azure SQL server. It hosts our SQL databases. We use it when we need a relational database backend. The result is a new SQL server instance. Example:

az sql server create --name mysqlserver --resource-group MyResourceGroup --location eastus --admin-user myadmin --admin-password MyPassword123

az sql db create

This command creates a new SQL database on a server. We use it to store structured data for our applications. It is a key command for setting up data tiers. The result is a new empty database. Example:

az sql db create --name mydatabase --resource-group MyResourceGroup --server mysqlserver

az cosmosdb create

We use this command to create an Azure Cosmos DB account. It is a globally distributed database service. We use it for NoSQL data needs like JSON or Graph. The result is a new Cosmos DB account. Example:

az cosmosdb create --name mycosmosdb --resource-group MyResourceGroup

Web App and Application Azure CLI Commands

These Azure CLI commands help us deploy and manage web applications and functions. They allow us to host websites and APIs easily.

az webapp create

We use this command to create a web app in an App Service plan. It hosts our web applications. We use this to deploy websites quickly. The result is a new web app container. Example:

az webapp create --resource-group MyResourceGroup --plan MyAppServicePlan --name MyWebApp

az webapp up

This command streamlines the deployment of a web app. It creates resources and deploys code from a local folder. We use it for quick deployment from the command line. The result is a running web application. Example:

az webapp up --name MyWebApp --resource-group MyResourceGroup --location eastus

az webapp list

We use this command to list all web apps in our subscription. It helps us track our hosted applications. The result displays all web app names and statuses. Example:

az webapp list --output table

az webapp deployment slot create

This command creates a new deployment slot for a web app. We use slots to stage updates before production. It allows for safe testing. The result is a new slot like staging. Example:

az webapp deployment slot create --name MyWebApp --resource-group MyResourceGroup --slot staging

az webapp config set

We use this command to change configuration settings for a web app. We can set framework versions or logging options. It helps us tune our application behavior. The result updates the app configuration. Example:

az webapp config set--name MyWebApp --resource-group MyResourceGroup --php-version7.4

az functionapp create

We use this command to create an Azure Function app. It hosts serverless code functions. We use it for event-driven architectures. The result is a new function app ready for code. Example:

az functionapp create --resource-group MyResourceGroup --consumption-plan-location eastus --runtimenode--name MyFunctionApp --storage-account mystorageaccount

Container and Kubernetes Azure CLI Commands

Modern applications often run in containers. These Azure CLI commands help us manage Azure Container Registry and Azure Kubernetes Service (AKS).

acr create

We use this command to create an Azure Container Registry. It stores our Docker images privately. We use it to secure our container artifacts. The result is a new registry instance. Example:

az acr create --resource-group MyResourceGroup --name MyRegistry --sku Basic

acr build

This command builds a Docker image and pushes it to the registry. We use it to compile and store images in one step. It simplifies the CI/CD pipeline. The result is a new image in the registry. Example:

az acr build -t myimage:latest -r MyRegistry .

az aks create

We use this command to create an Azure Kubernetes Service cluster. It orchestrates our container workloads. We use this to deploy complex microservices. The result is a managed Kubernetes cluster. Example:

az aks create --resource-group MyResourceGroup --name MyAKSCluster --node-count3--enable-addons monitoring --generate-ssh-keys

az aks get-credentials

This command downloads the credentials for the Kubernetes cluster. It lets kubectl communicate with our AKS cluster. We use this to manage the cluster locally. The result merges the context into our kubeconfig file. Example:

az aks get-credentials --resource-group MyResourceGroup --name MyAKSCluster

az aks scale

We use this command to change the number of nodes in the AKS cluster. We scale up to handle more load or down to save money. It adjusts the compute capacity. The result is a cluster with a new node count. Example:

az aks scale --resource-group MyResourceGroup --name MyAKSCluster --node-count5

az aks update

This command updates an existing AKS cluster configuration. We can upgrade the Kubernetes version or enable features. We use this to maintain our cluster. The result applies the updates. Example:

az aks update --resource-group MyResourceGroup --name MyAKSCluster --upgrade-cluster-version

az container create

We use this command to create an Azure Container Instance. It runs a container instantly without managing a server. We use it for quick jobs or testing. The result is a running container group. Example:

az container create --resource-group MyResourceGroup --name mycontainer --image myregistry.azurecr.io/myimage:v1

Monitoring and Troubleshooting Azure CLI Commands

We need to keep an eye on our resources. These Microsoft Azure CLI commands help us view logs and performance metrics.

az monitor activity-log list

We use this command to list entries in the activity log. It shows administrative operations on resources. We use it to audit changes or find errors. The result displays a list of log events. Example:

az monitor activity-log list --resource-group MyResourceGroup

az monitor metrics list

This command lists the metric values for a resource. We use it to check performance data like CPU or memory. It helps us understand resource usage. The result shows the numerical metrics. Example:

az monitor metrics list --resource /subscriptions/.../resourceGroups/MyResourceGroup/providers/Microsoft.Compute/virtualMachines/MyVM --metric"Percentage CPU"

az vm diagnostics get-boot-diagnostics-logs

We use this command to get the boot diagnostics logs for a VM. It helps us troubleshoot why a VM failed to start. It captures the console output and screenshot. The result downloads the log files. Example:

az vm diagnostics get-boot-diagnostics-logs --resource-group MyResourceGroup --name MyVM

az group deployment list

We use this command to list all deployments for a resource group. It shows the history of template deployments. We use it to see what changes were applied. The result lists the deployment history. Example:

az group deployment list --resource-group MyResourceGroup

Conclusion

Mastering these Azure CLI commands gives us the power to control our entire cloud environment. By practising these commands, we become more efficient and confident in managing our infrastructure. We encourage you to use this guide as your daily reference.

You can also check out this article for the best cloud deployment practices:
5 Cloud Deployment Best Practices You Should Know About

Microsoft Official Reference:
https://learn.microsoft.com/en-us/cli/azure/?view=azure-cli-latest

Aditya Gupta
Aditya Gupta
Articles: 487
Review Your Cart
0
Add Coupon Code
Subtotal