Scenario
You’re starting to work more with Azure and want a faster, more efficient way to manage resources. Clicking through the Azure Portal works, but it’s slow, repetitive, and not ideal for automation. You’ve heard about the Azure CLI a powerful command‑line tool that lets you create, manage, and automate Azure resources with simple commands.
But if you’re new to it, the CLI can feel intimidating.
This guide walks you through the basics of installing, logging in, and using the Azure CLI so you can confidently manage Azure from your terminal.
Lab Objectives
- Install the Azure CLI
- Log in and authenticate
- Use common Azure CLI commands
- Create and manage Azure resources
- Understand how the CLI fits into automation workflows
Prerequisites
- Azure subscription
- Windows, macOS, or Linux machine
- Basic command‑line familiarity
Why use the CLI
The Azure portal is a great guided way to setup resources in Azure to build infrastructure. Point and click works well and is an easy way to get things done, however it doesn't scale very well, meaning spinning up many resources would take an unreasonable amount of time and is liable to user error.
It's key benefits include:
- Speed - Run commands faster than navigating the Azure portal.
- Scripting - Automate deployments in Bash, PowerShell, or pipelines.
- Portability - Works across Linux, macOS, and Windows.
- Consistency - Unified commands with clean, repeatable and predictable output.
Install Azure CLI
Azure CLI can be installed by heading over to Microsoft’s official guide and choosing your OS to see the instructions for your OS. On Windows, the easiest way is to install via winget.
winget install --id Microsoft.AzureCLIWhichever method or OS you choose, the installation can be verified by outputting the version installed. All commands start with az.
az version
Log In
Before trying to run any commands, we need to connect to my Azure tenant. A browser window appears and I enter my credentials to authenticate to my Azure account.
az login --tenant <tenantID>
For those of you not used to using the command line, don't worry, the format of commands is quite straight forward:

Create a Resource Group
Resources in Azure live in resources groups, so I set that up first using uksouth as the nearest location to me.
az group create `
--name MyResourceGroup `
--location uksouth
Once the command has completed successfully, we can use the list command to list all groups. The --output flag is useful to format the results shown on screen, I prefer the table view output.
az group list --output table
Create a private VNet and Subnet
Now let’s build a virtual network and a subnet for the Windows Server.
az network vnet create `
--name MyVNet `
--resource-group MyResourceGroup `
--location uksouth `
--address-prefix 10.0.0.0/16 `
--subnet-name MySubnet `
--subnet-prefix 10.0.1.0/24Deploy a Windows Server VM
When creating the virtual machine, I used the Win2022DataCenter image. You can list the images available by running the command az vm image list --publisher MicrosoftWindowsServer --location uksouth --offer WindowsServer --output table
I also used the VM size of Standard_D2s_v3. You can check which VM sizes are available in your region by running the command az vm list-sizes --location uksouth --output table | Select-String "Standard_D2"
Since I don't need an NSG or public IP address for this VM, I use double quotes wrapped in single quotes.
az vm create `
--name MyWinVM `
--resource-group MyResourceGroup `
--image Win2022DataCenter `
--vnet-name MyVNet `
--subnet MySubnet `
--admin-username rajinder `
--admin-password "LabUser12345" `
--nsg '""' `
--public-ip-address '""' `
--size Standard_D2s_v3Deploy Azure Bastion
I'll use Azure Bastion to connect to the VM in my private virtual network. First I create a public IP address named MyBastionIP.
az network public-ip create `
--name MyBastionIP `
--resource-group MyResourceGroup `
--sku Standard `
--location uksouth
Then I create the mandatory Bastion subnet that Azure requires with the required name AzureBastionSubnet and subnet address of 10.0.10.0/26.
az network vnet subnet create `
--name AzureBastionSubnet `
--resource-group MyResourceGroup `
--vnet-name MyVNet `
--address-prefix 10.0.10.0/26Finally, I create Bastion. The enable-tunneling and enable-ip-connect are required when connecting to the VM using RDP from the Azure CLI.
az network bastion create `
--name MyBastion `
--resource-group MyResourceGroup `
--location uksouth `
--vnet-name MyVNet `
--public-ip-address MyBastionIP `
--enable-tunneling true `
--enable-ip-connect true
Securely connect to the Windows Sever VM using RDP
Running this command opens a Remote Desktop session as if connecting to a local VM.
az network bastion rdp `
--name MyBastion `
--resource-group MyResourceGroup `
--target-ip-address <VMprivateip>Explore useful Azure CLI commands
Hopefully, you are now familiar with running CLI commands, here's some handy commands you can try as well.
To view your subscription:
az account show --output tableTo list resource groups:
az group list --output tableTo check VM status:
az vm list --show-details --output tableTo get IP info:
az vm list-ip-addresses `
--name MyWinVM `
--resource-group MyResourceGroup `
--output tableTo stop a VM:
az vm stop --resource-group MyResourceGroup --name MyWinVMConclusion
Azure CLI puts cloud control in your hands, from provisioning infrastructure to automating deployments. Once you're comfortable with these basics, you can expand into scripting, containers, ARM templates, and advanced networking.