| Azure PowerShell | Azure CLI | |
|---|---|---|
| Command shape | Verb-AzNoun cmdlets |
az group subgroup command --flag value |
| Sign-in | Connect-AzAccount |
az login |
| Example | Restart-AzVM -ResourceGroupName rg-devops-lab -Name vm-web-01 |
az vm restart -g rg-devops-lab -n vm-web-01 |
| Line continuation | Backtick ` |
Backslash \ (Bash) |
| Results | PowerShell objects | JSON (change with -o table/tsv/yaml) |
flowchart LR U["You"] --> PS["Azure PowerShell<br/>New-AzVM, Get-AzResourceGroup"] U --> CLI["Azure CLI<br/>az vm create, az group list"] PS --> ARM["Azure Resource Manager"] CLI --> ARM
Both call the same Azure Resource Manager, so the results are the same; pick by team habit and script environment (PowerShell or Bash). Both work interactively and in scripts.
Looking commands up
az find "az vm"suggests popular commands and examples.az vm create --help(or-h) lists parameters, required ones and examples.- PowerShell:
Get-Help New-AzVM -Examples.
Traps: do not mix the syntaxes (az New-AzVM or Get-AzVM -g); and the old image alias UbuntuLTS is gone — use Ubuntu2204 (or a full URN):
New-AzVM -ResourceGroupName rg-devops-lab -Name vm-test -Image Ubuntu2204
| Command | Meaning |
|---|---|
az find "az vm" |
Suggest VM commands |
az vm create --help |
Parameters of az vm create |
Installing and updating
| Tool | Install | Update |
|---|---|---|
| Azure CLI | Windows installer or winget install Microsoft.AzureCLI, brew install azure-cli, Microsoft's apt/dnf repository |
az upgrade |
| Azure PowerShell | Install-Module -Name Az -Scope CurrentUser |
Update-Module -Name Az |
Both run on Windows, macOS, and Linux; Azure PowerShell needs PowerShell 7 for cross-platform use.
Signing in for automation
Interactive az login opens a browser. Scripts and pipelines use non-interactive options instead: az login --service-principal -u <app-id> --tenant <tenant-id> with a certificate or federated credential, or az login --identity on a VM or container that has a managed identity. PowerShell has Connect-AzAccount -Identity for the same purpose. Avoid storing passwords or client secrets in scripts.
Context and defaults
az account set and Set-AzContext choose the subscription. az config set defaults.group=rg-devops-lab defaults.location=southeastasia saves you from repeating -g and -l. Get-AzContext shows the current PowerShell context.
Shaping output
--query takes a JMESPath expression to filter the JSON before printing:
az vm list --query "[?location=='southeastasia'].{name:name, size:hardwareProfile.vmSize}" -o table
az group show -n rg-devops-lab --query id -o tsv
-o tsv gives bare values that drop straight into shell variables, and -o jsonc adds colour. In PowerShell, pipe objects into Where-Object and Select-Object instead.
Extensions and troubleshooting
Some command groups ship as extensions; az extension list-available -o table shows them and many install on first use. --debug prints the underlying REST calls, and --only-show-errors hides warnings in scripts.