Get started with Azure CLI
Welcome to the Azure Command-Line Interface (CLI)! This article introduces the CLI and helps you complete common tasks.
Install or run in Azure Cloud Shell
The easiest way to learn how to use the Azure CLI is by running a Bash environment in Azure Cloud Shell through your browser. To learn about Cloud Shell, see Quickstart for Bash in Azure Cloud Shell.
When you're ready to install the Azure CLI, see the installation instructions for Windows, Linux, macOS, and Docker container. If you're using the Azure classic deployment model, install the Azure classic CLI.
Check your version by running az --version
. Azure Cloud Shell always has the latest version of the Azure CLI preinstalled.
az version
Sign into the Azure CLI
Before using any Azure CLI commands with a local install, you need to sign in with az login.
Run the
az login
command.az login
If the Azure CLI can open your default browser, it initiates authorization code flow and opens the default browser to load an Azure sign-in page.
Otherwise, it initiates the device code flow and instructs you to open a browser page at https://aka.ms/devicelogin. Then, enter the code displayed in your terminal.
If no web browser is available or the web browser fails to open, you may force device code flow with az login --use-device-code.
Sign in with your account credentials in the browser.
After logging in, you receive a list of subscriptions associated with your Azure account. The
subscription information with isDefault: true
is the currently activated subscription after
logging in. To select another subscription, use the az account set
command with the subscription ID of the desired account. For more information about subscription selection,
see Manage Azure subscriptions.
There are ways to sign in non-interactively, which are covered in detail in Sign in with Azure CLI.
Find commands
Azure CLI commands are organized as command groups. Each group represents an area of an Azure service. There are two options to find command groups:
Use the az find command. For example, to search for command names containing
vm
, use the following command:az find vm
Use the
--help
argument to get a complete list of subgroups within a reference group. This example returns all the subgroups for virtual machines:az vm --help
Here is example output with lines omitted for brevity:
Subgroups: application : Manage applications for VM. availability-set : Group resources into availability sets. boot-diagnostics : Troubleshoot the startup of an Azure Virtual Machine. ...
Here's another example that finds the Azure CLI commands for grouping virtual machines into availability sets, a subgroup of
az vm
:az vm availability-set --help
Also use
--help
to get parameter lists and command examples for a reference command.az vm create --help
Here is example output with lines omitted for brevity:
Arguments --name [Required] : Name of the virtual machine. ... Authentication Arguments --admin-password : Password for the VM if authentication type is 'Password'. --admin-username : Username for the VM... ... Managed Service Identity Arguments ... Examples Create a VM from a custom managed image. az vm create -g MyResourceGroup -n MyVm --image MyImage ...
Use the A to Z reference index that lists all command groups alphabetically.
Find published samples and articles
If you prefer to learn Azure CLI syntax by seeing tested published examples, there are two indexes of article content:
Samples index A to Z. The samples index provides a list of Azure CLI samples sorted by subject area, reference group, and GitHub repository.
Article index A to Z. Use your keyboard
find
shortcut keys, likeCtrl + F
, to drop quickly to the reference command group in which you're interested. For example, the article index looks something like this foraz vm
:Reference subgroup Azure CLI article showing reference use az vm Output formats for Azure CLI commands How to use variables in Azure CLI commands Get VM information with queries {More articles listed here.} az vm aem New Version of Azure VM extension for SAP solutions Standard Version of Azure VM extension for SAP solutions az vm application {...}
Use tab completion
The CLI has full tab completion for commands in a Bash environment. To enable tab completion in a PowerShell environment, see Enable tab completion in PowerShell.
Be aware of globally available arguments
There are some arguments that are available for most commands.
--help
prints CLI reference information about commands and their arguments and lists available subgroups and commands.--output
changes the output format. The available output formats arejson
,jsonc
(colorized JSON),tsv
(Tab-Separated Values),table
(human-readable ASCII tables), andyaml
. By default the CLI outputsjson
. To learn more about the available output formats, see Output formats for Azure CLI.--query
uses the JMESPath query language to filter the output returned from Azure services. To learn more about queries, see Query command results with Azure CLI and the JMESPath tutorial.--verbose
prints information about resources created in Azure during an operation, and other useful information.--debug
prints even more information about CLI operations, used for debugging purposes. If you find a bug, provide output generated with the--debug
flag on when submitting a bug report. It can be used, for example, to identify the REST API that the command executed is invoking underneath, and the response received from the service.--subscription
is the name or ID of a subscription. For more information about setting your default subscription, see Manage Azure subscriptions with the Azure CLI.--only-show-errors
suppresses warnings in command output and only shows errors.
Use interactive mode
The CLI offers an interactive mode that automatically displays help information and makes it easier to select subcommands. You enter interactive mode with the az interactive command.
az interactive
For more information on interactive mode, see Run the Azure CLI in Interactive Mode.
There's also a Visual Studio Code plugin that offers an interactive experience, including autocomplete and mouse-over documentation.
Learn Azure CLI basics with quickstarts and tutorials
To learn how to use the Azure CLI, try our onboarding tutorial that teaches you the following skills while working with Azure Storage:
- Find and change your default subscription.
- Create an Azure resource containing a random ID in the name.
- Set environment variables.
- Learn syntax differences between Bash, PowerShell, and Cmd.
- Debug Azure CLI reference commands.
- Get properties from a local JSON file.. This example shows how to get configuration values for development, stage, and production.
- Delete multiple resources using a script.
Note
In scripts and on the Microsoft documentation site, Azure CLI examples are written for the
Bash shell. Most one-line examples will run on any platform. Longer examples which include line
continuations (\
), variable assignment, or quotes need to be modified to work in other shells,
including PowerShell. For more information on syntax differences between environments,
see Learn syntax differences between Bash, PowerShell, and Cmd.
Give feedback
We welcome your feedback for the CLI to help us make improvements and resolve bugs. You can file an issue on GitHub or use the built-in features of the CLI to leave general feedback with the az feedback command.
az feedback
See also
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for