You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
While the Azure Portal provides a rich graphical interface, many tasks are faster, more repeatable, and more scriptable when performed from the command line. Azure provides two primary command-line tools — the Azure CLI and Azure PowerShell — along with Azure Cloud Shell, a browser-based shell environment that comes pre-configured with both.
The Azure CLI (az) is a cross-platform command-line tool for managing Azure resources. It is available on Windows, macOS, and Linux, and can also be used directly in Azure Cloud Shell.
Key characteristics of the Azure CLI:
az <group> <subgroup> <action> --parametersYou can install the Azure CLI on your local machine:
# macOS (using Homebrew)
brew install azure-cli
# Ubuntu / Debian
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
# Windows (using MSI installer or winget)
winget install Microsoft.AzureCLI
After installation, verify it is working:
az version
Before using the CLI, you must authenticate:
# Interactive browser-based login
az login
# Login with a specific tenant
az login --tenant <tenant-id>
# Login using a service principal (for automation)
az login --service-principal -u <app-id> -p <password> --tenant <tenant-id>
After logging in, you can set the default subscription:
az account set --subscription "My Subscription Name"
Here are some of the most frequently used Azure CLI commands:
# Create a resource group
az group create --name myResourceGroup --location uksouth
# List all resource groups
az group list --output table
# Delete a resource group (and all resources inside it)
az group delete --name myResourceGroup --yes --no-wait
# Create a Linux VM
az vm create \
--resource-group myResourceGroup \
--name myVM \
--image Ubuntu2204 \
--admin-username azureuser \
--generate-ssh-keys
# List all VMs in a resource group
az vm list --resource-group myResourceGroup --output table
# Stop (deallocate) a VM
az vm deallocate --resource-group myResourceGroup --name myVM
# Start a VM
az vm start --resource-group myResourceGroup --name myVM
# Create a storage account
az storage account create \
--name mystorageaccount \
--resource-group myResourceGroup \
--location uksouth \
--sku Standard_LRS
# List storage accounts
az storage account list --output table
Every command supports the --help flag:
az vm --help
az vm create --help
By default, the Azure CLI returns results in JSON. You can change this:
# Table format — human-readable columns
az vm list --output table
# TSV format — tab-separated values for scripting
az vm list --output tsv
# JSON format (default) — full detail
az vm list --output json
# YAML format
az vm list --output yaml
You can also use the --query parameter with JMESPath expressions to filter results:
# Get just the names of all VMs
az vm list --query "[].name" --output tsv
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.