Azure CLI vs Azure PowerShell
Equivalent Azure CLI and Azure PowerShell commands side by side for sign-in, resource groups, VMs, storage, networks and roles.
By the tools4free.dev team · Last reviewed 4 December 2026
How to use this reference
Azure has two official command-line tools for managing resources. The Azure CLI is a single program called az that you run from any shell. Its commands are nouns followed by verbs, such as az group create, and it prints JSON by default. Azure PowerShell is the Az module for PowerShell. Its commands follow PowerShell's verb-noun pattern, such as New-AzResourceGroup, and they return .NET objects that you can pipe into other cmdlets. PowerShell 7 or higher is the recommended version of PowerShell for the Az module on all platforms, and the module is cross-platform and preinstalled in Azure Cloud Shell.
Both tools call the same Azure Resource Manager service, so anything one can do the other can usually do too. Neither is better. Choose the one that matches the shell your team already uses. Bash scripts and pipelines tend to use the CLI, while Windows administrators and PowerShell scripts tend to use Az. The tables below pair each task with the equivalent command in both tools, with the parameters you almost always need. Replace the placeholder names with your own, and check the full parameter list in the official reference before you rely on a command in a script.
Three habits differ between the tools. The CLI uses short, lower-case flags with two dashes (--resource-group, with -g as a short form), while PowerShell uses PascalCase parameters with one dash (-ResourceGroupName). The CLI sets a default subscription with az account set, while PowerShell keeps a context that you change with Set-AzContext. And in the CLI the same --query and --output flags work on every command, while PowerShell uses its normal pipeline (Where-Object, Select-Object, Format-Table). Exam-focused study notes on the same topic are on the AZ-104 CLI and PowerShell page.
The commands you will use most
az login or Connect-AzAccount), pick the subscription (az account set or Set-AzContext), then create a resource group first. Nearly every other resource must live in one.Sign in and choose a subscription
Sign in once per session. The CLI uses Web Account Manager on Windows and a browser on Linux and macOS by default, and falls back to device code login when neither is available. Both tools can also sign in as a service principal or a managed identity.
| Task | Azure CLI | Azure PowerShell |
|---|---|---|
| Sign in interactively | az login | Connect-AzAccount |
| Sign in to a specific tenant | az login --tenant TENANT_ID | Connect-AzAccount -Tenant TENANT_ID |
| Sign in as a service principal | az login --service-principal --username APP_ID --password CLIENT_SECRET --tenant TENANT_ID | Connect-AzAccount -ServicePrincipal -TenantId TENANT_ID -Credential $Credential |
| Sign in with a managed identity | az login --identity | Connect-AzAccount -Identity |
| List subscriptions | az account list | Get-AzSubscription |
| Show the current subscription | az account show | Get-AzContext |
| Switch subscription | az account set --subscription SUBSCRIPTION | Set-AzContext -Subscription SUBSCRIPTION |
| Sign out | az logout | Disconnect-AzAccount |
Microsoft strongly discourages passing a password on the command line with az login --username, and that form does not work with Microsoft accounts or accounts that have multi-factor authentication enabled. Use the interactive sign-in for people and a service principal or managed identity for automation.
Resource groups
A resource group is the container for related resources, and deleting it deletes everything inside.
| Task | Azure CLI | Azure PowerShell |
|---|---|---|
| Create | az group create --name myRG --location westus | New-AzResourceGroup -Name myRG -Location westus |
| Create with tags | az group create --name myRG --location westus --tags env=dev | New-AzResourceGroup -Name myRG -Location westus -Tag @{env="dev"} |
| List | az group list | Get-AzResourceGroup |
| Show one | az group show --name myRG | Get-AzResourceGroup -Name myRG |
| Delete without a prompt | az group delete --name myRG --yes --no-wait | Remove-AzResourceGroup -Name myRG -Force -AsJob |
Virtual machines
Both tools can create a VM from a short list of parameters. Give az vm create an image alias and, for Linux, --generate-ssh-keys. New-AzVM takes its login details through -Credential. Image aliases such as Ubuntu2204 are documented for both commands.
| Task | Azure CLI | Azure PowerShell |
|---|---|---|
| Create a VM | az vm create --resource-group myRG --name myVM --image Ubuntu2204 --generate-ssh-keys | New-AzVM -ResourceGroupName myRG -Name myVM -Location westus -Image Ubuntu2204 -Credential (Get-Credential) |
| Choose a size on create | az vm create ... --size Standard_D2s_v3 | New-AzVM ... -Size Standard_D2s_v3 |
| List VMs in a group | az vm list --resource-group myRG | Get-AzVM -ResourceGroupName myRG |
| Show one VM | az vm show --resource-group myRG --name myVM | Get-AzVM -ResourceGroupName myRG -Name myVM |
| Show power state | az vm show --resource-group myRG --name myVM --show-details | Get-AzVM -ResourceGroupName myRG -Name myVM -Status |
| Start | az vm start --resource-group myRG --name myVM | Start-AzVM -ResourceGroupName myRG -Name myVM |
| Restart | az vm restart --resource-group myRG --name myVM | Restart-AzVM -ResourceGroupName myRG -Name myVM |
| Stop but keep compute allocated (still billed) | az vm stop --resource-group myRG --name myVM | Stop-AzVM -ResourceGroupName myRG -Name myVM -StayProvisioned |
| Stop and release compute | az vm deallocate --resource-group myRG --name myVM | Stop-AzVM -ResourceGroupName myRG -Name myVM -Force |
| Delete | az vm delete --resource-group myRG --name myVM --yes | Remove-AzVM -ResourceGroupName myRG -Name myVM -Force |
The stop commands are a classic exam trap. az vm stop powers the VM off, but the VM continues to be billed. To avoid that, use az vm deallocate. In PowerShell, -StayProvisioned stops the VM without deallocating it, and the account is charged for the stopped VM. Without that switch, Stop-AzVM deallocates. -Force only skips the confirmation prompt.
Storage accounts
Storage account names must be globally unique. The SKU sets the redundancy, such as Standard_LRS or Standard_GRS, and the kind is usually StorageV2.
| Task | Azure CLI | Azure PowerShell |
|---|---|---|
| Create | az storage account create --name mystorageacct --resource-group myRG --location westus --sku Standard_LRS --kind StorageV2 | New-AzStorageAccount -ResourceGroupName myRG -Name mystorageacct -Location westus -SkuName Standard_LRS -Kind StorageV2 |
| List in a group | az storage account list --resource-group myRG | Get-AzStorageAccount -ResourceGroupName myRG |
| Show one | az storage account show --name mystorageacct --resource-group myRG | Get-AzStorageAccount -ResourceGroupName myRG -Name mystorageacct |
| List access keys | az storage account keys list --account-name mystorageacct --resource-group myRG | Get-AzStorageAccountKey -ResourceGroupName myRG -Name mystorageacct |
| Delete | az storage account delete --name mystorageacct --resource-group myRG --yes | Remove-AzStorageAccount -ResourceGroupName myRG -Name mystorageacct -Force |
Virtual networks and subnets
The CLI creates a network and its first subnet in one command. PowerShell builds a subnet configuration object first, then passes it to the network command. Adding a subnet to an existing network in PowerShell is a two-step change: add the configuration to the object, then save it with Set-AzVirtualNetwork.
| Task | Azure CLI | Azure PowerShell |
|---|---|---|
| Create a VNet with a subnet | az network vnet create --name myVNet --resource-group myRG --address-prefixes 10.0.0.0/16 --subnet-name web --subnet-prefixes 10.0.1.0/24 | $s = New-AzVirtualNetworkSubnetConfig -Name web -AddressPrefix 10.0.1.0/24; New-AzVirtualNetwork -Name myVNet -ResourceGroupName myRG -Location westus -AddressPrefix 10.0.0.0/16 -Subnet $s |
| List VNets | az network vnet list --resource-group myRG | Get-AzVirtualNetwork -ResourceGroupName myRG |
| Show one VNet | az network vnet show --name myVNet --resource-group myRG | Get-AzVirtualNetwork -Name myVNet -ResourceGroupName myRG |
| Add a subnet | az network vnet subnet create --resource-group myRG --vnet-name myVNet --name data --address-prefixes 10.0.2.0/24 | $v = Get-AzVirtualNetwork -Name myVNet -ResourceGroupName myRG; Add-AzVirtualNetworkSubnetConfig -Name data -VirtualNetwork $v -AddressPrefix 10.0.2.0/24 | Set-AzVirtualNetwork |
| Delete a VNet | az network vnet delete --name myVNet --resource-group myRG | Remove-AzVirtualNetwork -Name myVNet -ResourceGroupName myRG |
Role assignments (Azure RBAC)
A role assignment ties together a security principal, a role and a scope. In the CLI, --assignee accepts a user, group or service principal. In PowerShell, use -SignInName for a user principal name or -ObjectId for an object ID.
| Task | Azure CLI | Azure PowerShell |
|---|---|---|
| Assign a role at a scope | az role assignment create --assignee user@contoso.com --role Reader --scope /subscriptions/SUB_ID/resourceGroups/myRG | New-AzRoleAssignment -SignInName user@contoso.com -RoleDefinitionName Reader -Scope /subscriptions/SUB_ID/resourceGroups/myRG |
| Assign by object ID | az role assignment create --assignee-object-id OBJECT_ID --assignee-principal-type ServicePrincipal --role Reader --scope SCOPE | New-AzRoleAssignment -ObjectId OBJECT_ID -RoleDefinitionName Reader -Scope SCOPE |
| List assignments at a scope | az role assignment list --scope SCOPE | Get-AzRoleAssignment -Scope SCOPE |
| List the assignments of one user | az role assignment list --assignee user@contoso.com | Get-AzRoleAssignment -SignInName user@contoso.com |
| Remove an assignment | az role assignment delete --assignee user@contoso.com --role Reader --scope SCOPE | Remove-AzRoleAssignment -SignInName user@contoso.com -RoleDefinitionName Reader -Scope SCOPE |
| List role definitions | az role definition list | Get-AzRoleDefinition |
Run the list command with the same arguments before you delete. The CLI help warns that az role assignment delete removes all the role assignments that match the query, so a loose filter can remove more than you intended. The AZ-104 RBAC page explains scopes and role inheritance.
Filtering and formatting output
The CLI formats results with --output (or -o). The supported formats are json, jsonc, table, tsv, yaml, yamlc and none. The --query flag runs a JMESPath query on the result before it is printed. PowerShell has no such flags because its cmdlets return objects, so you filter and format with the pipeline.
| Task | Azure CLI | Azure PowerShell |
|---|---|---|
| Show a table | az group list --output table | Get-AzResourceGroup | Format-Table |
| Pick one field | az group list --query "[].name" --output tsv | (Get-AzResourceGroup).ResourceGroupName |
| Filter | az vm list --query "[?location=='westus']" | Get-AzVM | Where-Object Location -eq westus |
Which should you choose?
- Use the CLI when you work in Bash, in a pipeline on Linux, or in documentation that others will copy. Output is JSON, which suits JMESPath queries.
- Use Azure PowerShell when you already write PowerShell, want to pass objects between cmdlets, or need to combine Azure work with other Windows automation.
- Use either in Cloud Shell. The Az PowerShell module is preinstalled there, so there is nothing to set up.
- Prefer templates for repeatable builds. Imperative commands are fine for one-off work, but Bicep or ARM templates describe the end state and are easier to review. See the AZ-104 ARM and Bicep page.
Common mistakes
- Running a command against the wrong subscription. Check
az account showorGet-AzContextbefore you create or delete anything. - Mixing up stop and deallocate. A stopped but not deallocated VM still costs money.
- Using -Force or --yes without reading. These skip the confirmation prompt. Deleting a resource group removes everything in it.
- Writing secrets into scripts. Use a managed identity or prompted credentials instead of putting a client secret in a file.
- Assuming parameter names match. They do not.
--locationis-Location, but--skuis-SkuNameand--resource-groupis-ResourceGroupName. Look up each command.
To see what these commands changed, see the KQL cheat sheet, whose AzureActivity examples show who deleted resources.
Sources
- Azure CLI reference index (az login)
- az group, az vm, az storage account
- az network vnet, az network vnet subnet
- az role assignment, az role definition, az account
- Azure CLI output formats and JMESPath queries
- What is Azure PowerShell and Install Azure PowerShell
- Az.Accounts: Connect-AzAccount, Get-AzSubscription, Set-AzContext, Get-AzContext, Disconnect-AzAccount
- Az.Resources: New-AzResourceGroup, Get-AzResourceGroup, Remove-AzResourceGroup, New-AzRoleAssignment, Get-AzRoleAssignment, Remove-AzRoleAssignment, Get-AzRoleDefinition
- Az.Compute: New-AzVM, Get-AzVM, Start-AzVM, Stop-AzVM, Restart-AzVM, Remove-AzVM
- Az.Storage: New-AzStorageAccount, Get-AzStorageAccount, Remove-AzStorageAccount, Get-AzStorageAccountKey
- Az.Network: New-AzVirtualNetwork, Get-AzVirtualNetwork, Remove-AzVirtualNetwork, New-AzVirtualNetworkSubnetConfig, Add-AzVirtualNetworkSubnetConfig, Set-AzVirtualNetwork