Search⌘ K
AI Features

Azure CLI Commands Help

Explore the core Azure CLI commands to create and manage resources, use interactive mode for command assistance, and format outputs using JSON, YAML, or tables. Understand how to use command chaining, asynchronous execution, and persist configuration parameters for efficient Azure management.

CLI scope

Azure CLI offers a vast number of commands for the execution of various services. The key services include the following:

  • AI and ML
  • Analytics
  • Blockchain
  • Computing and containers
  • Databases and storage
  • DevOps and developer tools
  • IoT
  • Media
  • Mobile
  • Networking and security
  • Web

To learn the usage of a specific command, we use the command below:

Shell
az find

We can also run the CLI in the interactive mode using the az interactive command.

Run the terminal below to figure out what the find command does.

Also, let’s explore the az group command more, which helps us create a resource group (more on this later).

Terminal 1
Terminal
Loading...

To run the CLI in interactive mode, use the following command:

Shell
az interactive

We can get interactive support for commands (similar to autosuggest or spell corrections). Let’s try the interactive mode launched by the terminal below. Type any command, like az account or az group, and it will show the interactive help.

Terminal 1
Terminal
Loading...

Now, let’s learn more about the standard and important command groups for Azure CLI. We can create, delete, and manage groups using the commands associated with each command group.

Azure Command Groups

Commands Groups

Description

az group

Create, delete, and manage resource groups and template deployments

az config

Manage Azure CLI configurations

az capacity

Manage Azure capacity

az cognitiveservices

Manage Azure Cognitive Services accounts

az datafactory

Manage Azure Data Factory

az deployment

Manage Azure Resource Manager template deployment

az deploymentmanager

Create and manage rollouts and deployments for the service

az ml

Manage Azure Machine Learning resources with the extension (preview)

az pipelines

Manage Azure Pipelines

az resource

Manage Azure resources (keyvault, storage, etc.)

az storage

Manage Azure Cloud Storage resources (Blob storage, table storage, storage accounts, etc.)

az vm

Manage Linux or Windows VMs

Command-line arguments and explanations

  • --help: Prints out CLI command help.
  • --output: Changes the output format (tsv, json, yaml, and so on).
  • --query: Returns filtered output using a query, as seen below:
C++
az group list --query "[?location=='eastus']"

The above command prints all the accounts in the 'eastus' region associated with the account.

  • --verbose: Prints more information about command execution, including created resources.
  • --debug: Prints more debugging information.

CLI can generate output in different formats.

  • json: JSON string. This is the default setting.

  • jsonc: Colorized JSON.

  • yaml: YAML is a human-readable alternative to JSON.

  • yamlc: Colorized YAML.

  • table: ASCII table with keys as column headings.

  • tsv: Tab-separated values with no keys.

  • none: No output other than errors and warnings.

Let’s learn with examples. Consider the command below, which displays all the subscriptions registered with the Microsoft account.

Shell
az account list

The above command generates an output in the following manner; the tenant ID in the output is masked here:

Java
{
"cloudName": "AzureCloud",
"homeTenantId": "###",
"id": "###",
"isDefault": true,
"managedByTenants": [],
"name": "Free Trial",
"state": "Enabled",
"tenantId": "###",
"user": {
"name": "###",
"type": "user"
}
}

Now, we want the output to be generated in the YAML format. We will add the output parameter with the YAML specification.

Shell
az account list --output yaml

The command output will be printed in the YAML schema, as shown below:

YAML
cloudName: AzureCloud
homeTenantId: ###
id: ###
isDefault: true
managedByTenants: []
name: Free Trial
state: Enabled
tenantId: ###
user:
name: ###
type: user

Miscellaneous features

  • The output of one command can be passed as an input to the other. The following example assigns an ID found by the az vm list command to a variable.
Shell
running_vm_ids=$(az vm list --resource-group MyResourceGroup --show-details \
--query "[?powerState=='VM running'].id" --output tsv)
echo $running_vm_ids
  • Asynchronous commands: Many commands offer a --no-wait parameter, which allows other commands to run. The following example creates a VM. Since it’s a long-running command, the user gets unblocked to execute other commands.
Shell
az vm create -n MyVm -g MyResourceGroup --image UbuntuLTS
  • Persisted commands: Use persisted commands to save the command-line arguments. Most of the Azure commands require configuration parameters like resource group and workspace. Instead of repeatedly using the same values, we can persist them for a session.
Shell
az config param-persist on
# With persisted parameters turned on, create a resource group
az group create --name RG1forTutorial --location eastus2
# See new persisted parameters
az config param-persist show

When we create the resource group, the values persist. When we print the persisted values, we can observe the output like this:

XML
{
"all": {
"location": "eastus2",
"resource_group_name": "RG1forTutorial"
}
}

This way, we can keep referring to the stored values.