The Azure Command-Line Interface (CLI) is an essential tool for any cloud professional. Mastering these commands will significantly reduce your manual overhead. In this guide, I will walk you through the most important Azure CLI examples for beginners. Once you learn the “az” syntax, you’ll never want to go back to clicking through menus.
Table of Contents
- Azure CLI Examples For Beginners
Azure CLI Examples For Beginners
What is Azure CLI and Why Should You Use It?
The Azure CLI is a cross-platform command-line tool used to create and manage Azure resources. It runs on Windows, macOS, and Linux, and even inside your browser via the Azure Cloud Shell.
Why I Prefer CLI Over the Portal:
- Speed: Executing a command is often faster than waiting for a UI to load.
- Automation: You can easily wrap these commands into scripts (Bash or PowerShell).
- Consistency: Scripts ensure that you deploy the exact same environment every time.
- Version Control: You can save your infrastructure logic in GitHub or GitLab.
Getting Started: Installation and Authentication
Before we dive into the examples, you need to have the environment ready. I always recommend checking your version first to ensure you are on the latest release.
1. Check Version
To see which version you are running, use:
az --version2. Logging In
To connect your local terminal to your Azure account, run:
az loginCheck out Az login –identity
Note: This will open a browser window asking you to authenticate with your Microsoft credentials.
3. Account Management
If you have multiple subscriptions (e.g., one for “Dev” and one for “Production”), you need to make sure you’re working in the right one.
- List all subscriptions:
az account list --output table- Set active subscription:
az account set --subscription "My-Subscription-Name"Core Resource Management: The Building Blocks
In Azure, everything starts with a Resource Group (RG). Think of an RG as a logical container for your resources—like a folder on your computer.
Creating a Resource Group
az group create --name MyResourceGroup --location eastusCommon Resource Group Commands
| Action | Command |
| List all groups | az group list --output table |
| Show specific group | az group show --name MyResourceGroup |
| Delete a group | az group delete --name MyResourceGroup --yes --no-wait |
Pro Tip: Use the
--no-waitflag if you don’t want to wait for the deletion to finish. It sends the command to Azure and frees up your terminal immediately.
Working with Azure Virtual Machines (VMs)
Managing VMs via the CLI is incredibly powerful. You can spin up a Linux or Windows server in seconds without navigating through twenty different configuration screens.
1. Create a Linux VM
Here is a standard example to create a basic Ubuntu server:
az vm create --resource-group MyResourceGroup --name MyUbuntuVM --image Ubuntu2204 --admin-username azureuser --generate-ssh-keys2. Managing VM Power States
If you’re looking to save costs, you should stop your VMs when they aren’t in use.
- Start VM:
az vm start --resource-group MyResourceGroup --name MyUbuntuVM- Stop VM:
az vm stop --resource-group MyResourceGroup --name MyUbuntuVM- Deallocate VM: (This is the one that actually stops the billing!)
az vm deallocate --resource-group MyResourceGroup --name MyUbuntuVMCheck out Azure VM Stopped Deallocated
3. List and Monitor VMs
To see all VMs in your subscription and their current status:
az vm list -d --query "[].{Name:name, Status:powerState}" --output tableStorage Account Examples
Storage is the backbone of almost every Azure solution. Whether you’re hosting a static website or storing logs, you’ll need to know these commands.
1. Create a Storage Account
Storage names must be globally unique. I usually append a random string or date to ensure there are no conflicts.
az storage account create --name mystorageacct2026 --resource-group MyResourceGroup --location eastus --sku Standard_LRSCheck out Create a storage account in Azure
2. Create a Blob Container
Once the account is ready, you need a container to hold your files.
az storage container create --name images --account-name mystorageacct20263. Uploading Files
To upload a local document (e.g., report.pdf) to your new container:
az storage blob upload --account-name mystorageacct2026 --container-name images --name my-report --file report.pdfNetworking Basics
Networking can be complex, but the CLI simplifies the creation of virtual networks (VNets) and security rules.
- Create a VNet:
az network vnet create --resource-group MyResourceGroup --name MyVNet --address-prefix 10.0.0.0/16 --subnet-name MySubnet --subnet-prefix 10.0.1.0/24- Open a Port (NSG Rule):If you have a web server on a VM and need to open port 80 for public traffic:
az network nsg rule create --resource-group MyResourceGroup --nsg-name MyVMNSG --name AllowHTTP --priority 100 --destination-port-ranges 80 --access Allow --protocol TcpAdvanced Tip: Using Queries and Output Formats
One of the most powerful features of the Azure CLI is the --query parameter. It uses JMESPath syntax to filter the JSON data that Azure returns.
Examples of Output Control:
- Table View: Best for humans to read. (
--output table) - JSON View: Best for scripts. (
--output json) - TSV View: Best for passing values to other commands. (
--output tsv)
Filter Example:
If I only want the IP address of a specific VM:
az vm list-ip-addresses --resource-group MyResourceGroup --name MyUbuntuVM --query "[0].virtualMachine.network.publicIpAddresses[0].ipAddress" --output tsvBest Practices for Beginners
- Use Variables: Instead of typing
MyResourceGrouptwenty times, save it to a variable:RG="MyResourceGroup". - Tag Everything: Always add tags to your resources for billing purposes. (
--tags Environment=Dev Project=Alpha) - The Help Command: If you get stuck, simply append
--helpto any command. For example:az vm create --help. - Interactive Mode: If you’re just learning, try
az interactive. It provides auto-completion and descriptions as you type.
Conclusion
The Azure CLI is more than just a tool; it’s a productivity multiplier. By mastering these basic examples—from resource groups to VMs and storage—you are setting yourself up for success in the cloud.
You may also like the following articles:
- Top 10 Azure CLI Commands You Must Know
- Azure CLI List All Resources
- Azure CLI Delete Resource Group
- Azure CLI Tutorial
- Azure CLI Command Lists

I am Rajkishore, and I am a Microsoft Certified IT Consultant. I have over 14 years of experience in Microsoft Azure and AWS, with good experience in Azure Functions, Storage, Virtual Machines, Logic Apps, PowerShell Commands, CLI Commands, Machine Learning, AI, Azure Cognitive Services, DevOps, etc. Not only that, I do have good real-time experience in designing and developing cloud-native data integrations on Azure or AWS, etc. I hope you will learn from these practical Azure tutorials. Read more.
