Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

azure
command line
scripting
web hosting

How to use Azure using the command line

Educative Answers Team

The Azure CLI

The Azure CLI is a cross-platform, command-line tool built-in Python that creates, updates, and removes nearly all Azure resources.

This shot is meant to be a brief overview of the Azure CLI. If you’d like to learn more about this topic, check out the Microsoft documentation.

No setup needed using Cloud Shell

To be used on the Cloud Shell, it comes pre-installed.

However, for local installations, check out these instructions to install it. It would help if you authenticated the Azure CLI using the command az login, and set the default subscription using az account set.

Run the following command to set the default subscription, changing the [subscription name] placeholder with the name of your subscription.

az account set --subscription '[subscription name]'

Commands and arguments

The Azure CLI is built around the premise of commands. The Azure CLI all stems from a single command called az, which kicks off the Azure CLI.

Command groups

Command groups are sets of commands all related to a particular Azure service.

For example, to manage subscriptions, you’d use the account command group. To manage Azure App Services, you’d use the app service command group. Inside each group, there are subgroups specific to each service.

Finding commands

Every Azure CLI command group and command has a universal --help argument, which shows all the options related to that command or group.

For example, at the root level, the following command returns all of the available groups and subgroups for the az command:

az --help

You can now drill down into any of the subgroups to explore more. Let’s say that you’d like to manage resource groups. Scrolling down a bit, you’ll see a subgroup called group. Provide that group as an argument to az with --help and see what happens. The command will be:

az group --help

Finding examples

We have the az find command to discover examples of using various commands and command groups.

The following command shows you the examples related to the storage account:

az find "az storage"

For example, the first command gives examples related to groups and the second command specifically provides examples related to group creation:

az find "az group"
az find "az group create"

Getting interactive

In this mode, you can begin typing groups and subgroups and be automatically prompted for required parameters. In the following screenshot, simply typing group create brought up available arguments and examples.

Interactive mode is like using --help and az find all at once as you type.

Azure CLI Interactive Mode
Azure CLI Interactive Mode

If you’d like to learn more about the interactive mode, check out the Azure CLI Interactive mode documentation.

Extensions

Using extensions, you can add on additional groups and commands if they don’t come pre-installed.

You can check all available extensions within the Azure CLI using the az extension list-available command. Try the following command:

az extension list-available --output table

The Azure CLI has a common set of arguments that are available on all commands; the ---output argument is one. You can learn about the other common arguments by visiting the Microsoft documentation.

Once you’ve found an extension, use the az extension add command to download and install it.

az extension add --name <extension-name>

You can update the extension to the latest version by using the az extension update command.

az extension update --name <extension-name>

Finally, you can also uninstall it using az extension remove.

az extension remove --name <extension-name>

RELATED TAGS

azure
command line
scripting
web hosting
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring