Home › Guides › Reference › Azure CLI vs Azure PowerShell

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

Sign in (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.

TaskAzure CLIAzure PowerShell
Sign in interactivelyaz loginConnect-AzAccount
Sign in to a specific tenantaz login --tenant TENANT_IDConnect-AzAccount -Tenant TENANT_ID
Sign in as a service principalaz login --service-principal --username APP_ID --password CLIENT_SECRET --tenant TENANT_IDConnect-AzAccount -ServicePrincipal -TenantId TENANT_ID -Credential $Credential
Sign in with a managed identityaz login --identityConnect-AzAccount -Identity
List subscriptionsaz account listGet-AzSubscription
Show the current subscriptionaz account showGet-AzContext
Switch subscriptionaz account set --subscription SUBSCRIPTIONSet-AzContext -Subscription SUBSCRIPTION
Sign outaz logoutDisconnect-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.

TaskAzure CLIAzure PowerShell
Createaz group create --name myRG --location westusNew-AzResourceGroup -Name myRG -Location westus
Create with tagsaz group create --name myRG --location westus --tags env=devNew-AzResourceGroup -Name myRG -Location westus -Tag @{env="dev"}
Listaz group listGet-AzResourceGroup
Show oneaz group show --name myRGGet-AzResourceGroup -Name myRG
Delete without a promptaz group delete --name myRG --yes --no-waitRemove-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.

TaskAzure CLIAzure PowerShell
Create a VMaz vm create --resource-group myRG --name myVM --image Ubuntu2204 --generate-ssh-keysNew-AzVM -ResourceGroupName myRG -Name myVM -Location westus -Image Ubuntu2204 -Credential (Get-Credential)
Choose a size on createaz vm create ... --size Standard_D2s_v3New-AzVM ... -Size Standard_D2s_v3
List VMs in a groupaz vm list --resource-group myRGGet-AzVM -ResourceGroupName myRG
Show one VMaz vm show --resource-group myRG --name myVMGet-AzVM -ResourceGroupName myRG -Name myVM
Show power stateaz vm show --resource-group myRG --name myVM --show-detailsGet-AzVM -ResourceGroupName myRG -Name myVM -Status
Startaz vm start --resource-group myRG --name myVMStart-AzVM -ResourceGroupName myRG -Name myVM
Restartaz vm restart --resource-group myRG --name myVMRestart-AzVM -ResourceGroupName myRG -Name myVM
Stop but keep compute allocated (still billed)az vm stop --resource-group myRG --name myVMStop-AzVM -ResourceGroupName myRG -Name myVM -StayProvisioned
Stop and release computeaz vm deallocate --resource-group myRG --name myVMStop-AzVM -ResourceGroupName myRG -Name myVM -Force
Deleteaz vm delete --resource-group myRG --name myVM --yesRemove-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.

TaskAzure CLIAzure PowerShell
Createaz storage account create --name mystorageacct --resource-group myRG --location westus --sku Standard_LRS --kind StorageV2New-AzStorageAccount -ResourceGroupName myRG -Name mystorageacct -Location westus -SkuName Standard_LRS -Kind StorageV2
List in a groupaz storage account list --resource-group myRGGet-AzStorageAccount -ResourceGroupName myRG
Show oneaz storage account show --name mystorageacct --resource-group myRGGet-AzStorageAccount -ResourceGroupName myRG -Name mystorageacct
List access keysaz storage account keys list --account-name mystorageacct --resource-group myRGGet-AzStorageAccountKey -ResourceGroupName myRG -Name mystorageacct
Deleteaz storage account delete --name mystorageacct --resource-group myRG --yesRemove-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.

TaskAzure CLIAzure PowerShell
Create a VNet with a subnetaz 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 VNetsaz network vnet list --resource-group myRGGet-AzVirtualNetwork -ResourceGroupName myRG
Show one VNetaz network vnet show --name myVNet --resource-group myRGGet-AzVirtualNetwork -Name myVNet -ResourceGroupName myRG
Add a subnetaz 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 VNetaz network vnet delete --name myVNet --resource-group myRGRemove-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.

TaskAzure CLIAzure PowerShell
Assign a role at a scopeaz role assignment create --assignee user@contoso.com --role Reader --scope /subscriptions/SUB_ID/resourceGroups/myRGNew-AzRoleAssignment -SignInName user@contoso.com -RoleDefinitionName Reader -Scope /subscriptions/SUB_ID/resourceGroups/myRG
Assign by object IDaz role assignment create --assignee-object-id OBJECT_ID --assignee-principal-type ServicePrincipal --role Reader --scope SCOPENew-AzRoleAssignment -ObjectId OBJECT_ID -RoleDefinitionName Reader -Scope SCOPE
List assignments at a scopeaz role assignment list --scope SCOPEGet-AzRoleAssignment -Scope SCOPE
List the assignments of one useraz role assignment list --assignee user@contoso.comGet-AzRoleAssignment -SignInName user@contoso.com
Remove an assignmentaz role assignment delete --assignee user@contoso.com --role Reader --scope SCOPERemove-AzRoleAssignment -SignInName user@contoso.com -RoleDefinitionName Reader -Scope SCOPE
List role definitionsaz role definition listGet-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.

TaskAzure CLIAzure PowerShell
Show a tableaz group list --output tableGet-AzResourceGroup | Format-Table
Pick one fieldaz group list --query "[].name" --output tsv(Get-AzResourceGroup).ResourceGroupName
Filteraz vm list --query "[?location=='westus']"Get-AzVM | Where-Object Location -eq westus

Which should you choose?

Common mistakes

To see what these commands changed, see the KQL cheat sheet, whose AzureActivity examples show who deleted resources.

Sources