New to Rust? Grab our free Rust for Beginners eBook Get it free →
Azure CLI Commands for Common Tasks

To inspect or change an Azure resource, use the command that matches the task. Azure CLI is Microsoft’s command-line interface for running commands against Azure services.
I’ll show how to check the active cloud and subscription, which sets the default resource scope, before inspecting a resource or making a change. I’ll also show how to run Azure CLI commands in PowerShell.
TL;DR
Azure CLI commands follow a group and action structure. Check the active cloud and subscription before a resource change.
- Start with az login and inspect az account show.
- Use az cloud list to see registered clouds.
- Choose JSON for structured output, tables for a quick scan, and --query to select fields.
What is Azure CLI?
Azure CLI is Microsoft’s cross-platform command-line interface for Azure services. Its executable is named az, and command groups organize operations by resource. The group-list and virtual-machine-list commands query different resource types.
A command generally has a group, an action and options. The resource-group creation example supplies a name and location. Generated help lists required arguments and accepted choices.
Azure PowerShell is a separate module with its own cmdlets and context. A session signed in through that module does not set Azure CLI account state.
How to use Azure CLI commands step by step
Begin with the target context, then inspect before changing a resource. Microsoft’s command reference documents each example below.
The Azure CLI project is maintained in the Azure organization’s GitHub repository. Its root includes implementation, documentation and development tooling. Repository navigation can help investigate behavior that the command reference does not explain.
Open the repository’s commit history when investigating a source example from an issue or discussion. Compare changed files with the installed CLI version. Use Microsoft’s command reference for supported syntax.
Folders separate project work. The source tree holds implementation code, while documentation and test areas serve other purposes. A folder name alone does not establish whether a command is available in your installed release.
On a repository page, start with the README for project scope and setup guidance. Follow documentation links to the command reference or release notes. Commit history explains when a file changed, while releases identify packaged versions.
For ordinary command use, install the supported Azure CLI distribution and consult its generated help. If a repository example and installed help disagree, record the CLI version and check Microsoft’s reference before changing a script.
The installation page lists supported methods for Linux, macOS and Windows. Choose the method maintained for the operating system, then open a fresh shell so its PATH includes the CLI executable. A successful version check confirms the command can start, but account commands still require sign-in.
Azure CLI’s command reference is organized by command group. The account group handles identity and subscription context, while resource groups and service groups expose resource operations. Begin with the group that matches the task, then inspect its generated help for required arguments and accepted values.
Step 1: Check the installation and sign in
Install Azure CLI using Microsoft’s supported method for your operating system, then check the executable before authenticating. Interactive sign-in normally opens a browser. Headless environments can use the documented device-code flow.
az --version
az login
# On a machine without a browser:
az login --use-device-code
In PowerShell, enter each command on its own line. Use Microsoft’s PowerShell examples for query quoting.
Step 2: Identify the cloud and subscription
The active cloud sets service endpoints and the subscription sets default resource scope. I checked for Azure CLI and found it absent. The shell returned a command-not-found error.
az cloud list --output table
az account list --output table
az account show --output table
az account set --subscription <subscription-name-or-id>
The cloud list shows registered environments and which one is active. The account list shows subscriptions in the current cloud. After selection, verify the subscription name, tenant and identifier before provisioning.
Account output can also expose tenant and subscription identifiers that help distinguish similar environments. Treat those values as operational context, not as credentials. A service principal may authenticate successfully while lacking access to an enabled subscription, so check the tenant and assigned access when the account list is empty.
Step 3: Find a resource group and inspect it
A resource group is a management container for related Azure resources. List groups in the chosen subscription, then inspect the exact target before creating resources or deleting anything.
az group list --output table
az group show --name demo-rg --output json
az group create --name demo-rg --location eastus
The create command requires a name and location. Check region availability with the account location-list command shown in Microsoft’s reference. If the group already exists, inspect it rather than treating a create error as proof that the target is safe to reuse.
Step 4: List a service’s resources
Start a service task with a read operation, narrow it to a resource group where supported, and choose output suited to the next step.
az vm list --resource-group demo-rg --output table
az storage account list --resource-group demo-rg --output table
az sql db list --resource-group demo-rg --server demo-sql
These are lookup examples, not a guarantee that each resource type exists in the group. SQL database listing also needs a server name. Use the virtual-machine list help or matching service reference when a command requires another scope value.
Use a resource-specific show operation when a list result leaves a property unclear. Keep the resource group, server or virtual-machine name in the command so the target is explicit. If a list returns no rows, check the active subscription before concluding that the resource is absent.
Step 5: Filter results with output options
Azure CLI returns JSON by default, and --query applies a JMESPath expression to command results. Use a table for interactive review or TSV when a script needs a simple field.
az account list --query "[?isDefault].name" --output tsv
az group list --query "[].{Name:name, Location:location}" --output table
az vm list --query "[].name" --output json
Azure CLI evaluates JMESPath queries against JSON results before formatting. Choose table output for a human scan or TSV for a script. Quoting varies across Bash, PowerShell and Command Prompt, so use the Microsoft query guide when a filter contains quotes or Boolean values.
Step 6: Run commands from PowerShell
PowerShell can run Azure CLI commands directly once Azure CLI is installed and available on PATH. Use PowerShell variables for values you need to reuse, and keep the command’s own quoting separate from PowerShell string syntax.
$rg = "demo-rg"
az group list --output table
az vm list --resource-group $rg --output table
These lines use PowerShell variable syntax. For automation, check the process exit code and avoid parsing a human-oriented table.
Step 7: Make a change only after review
Write commands create, update or remove cloud resources, so confirm the subscription and resource identifiers immediately before executing one. For example, Azure CLI documents VM start and stop operations with an explicit resource group and VM name.
az vm show --resource-group demo-rg --name demo-vm --output table
az vm start --resource-group demo-rg --name demo-vm
az vm deallocate --resource-group demo-rg --name demo-vm
Deallocate releases compute allocation, unlike stopping the guest operating system. Confirm the billing and availability effect for your workload. A read command checks resource state after the operation, but not application health.
Azure CLI command errors and safety checks
Command failures become clearer to diagnose when you separate executable, identity, subscription and resource-name problems. Check them in that order before changing permissions or retrying a destructive command.
| Symptom | Likely check | Next step |
|---|---|---|
| az: command not found | CLI is absent or not on PATH | Install through Microsoft’s guide, open a new shell, run az --version |
| No subscriptions found | Identity may lack subscription access, or the target tenant is wrong | Check tenant and role assignment with an administrator. do not assume login selected the intended subscription |
| Resource group not found | Wrong subscription, group name or cloud | Run az account show, then list groups in that scope |
| Unrecognized argument | Flag spelling, shell quoting or command version | Run the command’s --help reference and compare exact option names |
| Unexpected query output | JMESPath expression or shell escaping | First request JSON, then test a small query with shell-specific quoting |
The question “which Azure CLI command shows the various Azure clouds” has a direct answer: az cloud list. By contrast, az account list is for subscriptions, and the default list includes enabled subscriptions in the current cloud. These commands answer different context questions.
For a database deletion, inspect the target first. The code examples show inspection and deletion with database, resource-group and server names.
Do not paste passwords, service-principal secrets or access tokens into examples, shell history or shared logs. Automation should use an approved identity mechanism and the narrowest role needed. A successful sign-in proves authentication, not permission to every subscription or resource.
Conclusion
Azure CLI command names make sense when you treat account context as part of the command. Confirm the cloud and subscription, inspect the target, then make and verify one change.
For exact service syntax, use Microsoft’s Azure CLI reference, its query guide, and the subscription guide. For a related deployment checklist, see CodeForGeek’s cloud deployment best practices.
FAQ
These answers address common questions about running Azure CLI commands and selecting their context.
How do I run Azure CLI commands in PowerShell?
Install Azure CLI, open PowerShell, sign in with az login, then run az commands directly. Use PowerShell syntax for variables and shell-specific quoting for –query expressions.
Which Azure CLI command lists available clouds?
Run az cloud list. To see subscription context, use az account list or az account show instead.
How do I select an Azure subscription?
Run az account list, choose the intended subscription, then run az account set –subscription with its name or ID and verify with az account show.
How do I delete an Azure SQL database with Azure CLI?
Inspect the database and confirm the active cloud, subscription, resource group, server and database name first. The documented command is az sql db delete with those identifiers. do not add –yes unless skipping confirmation is intentional.




