Azure CLI: Installation to Interaction

shashi
4 min readAug 21, 2022

Interacting with Azure Cloud Platform

Azure offers three different ways to interact with the resource on the cloud:

Azure Web Portal (UI)

Azure SDKs or APIs

Azure CLIs

To access resources programmatically, generally, one of the two approaches is used:

Azure SDKs

Azure CLI

Installation of Azure CLI

The Azure CLI is available to install in Windows, macOS, and Linux environments. It can also be run in a Docker container and Azure Cloud Shell.

Installation on Windows

Azure CLI can be installed on Windows using an MSI(Microsoft Installer), which then gives access to the CLI via Command Prompt or PowerShell.

The MSI distributable is used to install and update the azure CLI, if you have an existing version, then the installer will automatically update your CLI to the latest version. You can easily download and install the Azure CLI for windows using this link.

Installation on macOS

Azure CLI is also available for installation on macOS. It offers the same commands to run through a terminal or via scripts. The installation of Azure CLI on macOS is available via the homebrew package manager. If you don’t have homebrew on your macOS, you can install the package via the following command

/bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Once the homebrew package is installed on your macOS, you can proceed to install Azure CLI on your macOS. You can install Azure CLI on macOS via the following command: brew install azure-cli

Interacting with Azure Resources using CLIs

Azure SDKs and CLIs offer entirely the same functionalities to access their cloud resources, but you get more granular control using Azure CLI. Azure CLI is a multi-platform tool that helps the developer or the end user to interact with Azure Resources. One can install Azure CLI on Mac, Windows, Linux, and any other OS out there. It can also be used from a browser through the Azure Cloud Shell or run from inside a Docker container. It allows the execution of commands through a terminal using interactive command-line prompts or a script.

Once you have installed the Azure CLI on your system, you can even automate a particular task using Azure CLI through a script. We can use multiple azure CLI to form a chain of command which then forms a script that in turn interacts with the cloud resources.

Authentication First

Before running any azure CLI command, you need to authenticate your system with azure. You can do so by, signing in with: az login . This will open your default browser and will prompt you to log in with your account to the Azure portal. After successful authentication, you may close the browser page or it will be redirected to the docs page after 10 secs.

If your browser is not available you can alternatively use the sign-in via device code option using the command : az login --use-device-code

az login

Interaction Next

Now you are all set to play around with Azure CLI and interact with your resource in the cloud. To interact with Azure resources, CLI offers various commands specific to those resources. Each command in Azure CLI starts with a az keyword, followed by the name of the resources. The next keyword in the CLI is the action that you want the CLI to perform. One basic command that you can run is to retrieve the list of accounts in azure subscription using the following command : az account list . This command will give you the following result.

You can find the entire reference to the Azure CLI here. There are a ton of resources on Azure that is useful for various different use cases. All these resources have their own CLI actions. But all these commands follow a general pattern. The Azure CLI syntax is a combination of groups, references, commands, and parameters. Often the full reference command is referred to as command.

--

--