What is the Azure CLI?
The Azure Command-Line Interface (CLI) is a cross-platform command-line tool to connect to Azure and execute administrative commands on Azure resources. It allows the execution of commands through a terminal using interactive command-line prompts or a script.
For interactive use, you first launch a shell such as cmd.exe on Windows, or Bash on Linux or macOS, and then issue a command at the shell prompt. To automate repetitive tasks, you assemble the CLI commands into a shell script using the script syntax of your chosen shell, and then you execute the script.
You can install the Azure CLI locally on Linux, Mac, or Windows computers. It can also be used from a browser through the Azure Cloud Shell or run from inside a Docker container.
Current Version
The current version of the Azure CLI is 2.49.0. For information about the latest release, see the release notes. To find your installed version and see if you need to update, run az version.
Data collection
Azure CLI collects telemetry data by default. Microsoft aggregates collected data to identify patterns of usage to identify common issues and to improve the experience of Azure CLI. Microsoft Azure CLI does not collect any private or personal data. For example, the usage data helps identify issues such as commands with low success and helps prioritize our work.
While we appreciate the insights this data provides, we also understand that not everyone wants to send usage data. You can disable data collection with the az config set core.collect_telemetry=false
command. You can also read our privacy statement to learn more.
Prepare your environment
Before running Azure CLI commands, you need to setup your environment.
Use the Bash environment in Azure Cloud Shell. For more information, see Quickstart for Bash in Azure Cloud Shell.
If you prefer to run CLI reference commands locally, install the Azure CLI. If you're running on Windows or macOS, consider running Azure CLI in a Docker container. For more information, see How to run the Azure CLI in a Docker container.
If you're using a local installation, sign in to the Azure CLI by using the az login command. To finish the authentication process, follow the steps displayed in your terminal. For other sign-in options, see Sign in with the Azure CLI.
When you're prompted, install the Azure CLI extension on first use. For more information about extensions, see Use extensions with the Azure CLI.
Run az version to find the version and dependent libraries that are installed. To upgrade to the latest version, run az upgrade.
Azure CLI examples
This article provides different Azure CLI examples for the following :
- Subscription syntax
- Role assignment syntax
- PowerShell syntax
Subscription syntax example
The Azure CLI syntax follows a simple reference name
- command
- parameter
- parameter value
pattern. For example, switching between subscriptions is often a common task. Here is the syntax.
az account set --subscription "my subscription name"
Now, how easy was that?! See Manage subscriptions with Azure CLI to learn more about using the Azure CLI to work with subscriptions and create management groups.
Role assignment syntax example
Another common use of the Azure CLI is managing role assignments.
az role assignment create --assignee servicePrincipalName --role Reader --scope /subscriptions/mySubscriptionID/resourceGroups/myResourceGroupName
az role assignment delete --assignee userSign-inName --role Contributor
See Create an Azure service principal with the Azure CLI for an in-depth turorial on managing service principals and role assignments.
PowerShell syntax comparison
Choose the right command-line tool explains the difference between tools
and environments
with an emphasis on the Azure CLI and Azure PowerShell. It also gives many side-by-side command comparisons. Here are two examples:
Command | Azure CLI | Azure PowerShell |
---|---|---|
Create Resource Group | az group create --name <ResourceGroupName> --location eastus | New-AzResourceGroup -Name <ResourceGroupName> -Location eastus |
Create Azure Storage Account | az storage account create --name <StorageAccountName> --resource-group <ResourceGroupName> --location eastus --sku Standard_LRS --kind StorageV2 | New-AzStorageAccount -Name <StorageAccountName> -ResourceGroupName <ResourceGroupName> -Location eastus -SkuName Standard_LRS -Kind StorageV2 |
See Also
Feedback
Submit and view feedback for