Azure CLI Tutorials: Installations and User Guide

What is Azure CLI?

The Azure Command-Line Interface (CLI) is a cross-platform command-line tool that allows you to manage Azure resources from the command line. With the Azure CLI, you can create, manage, and delete Azure resources, such as virtual machines, storage accounts, and databases. You can also use the Azure CLI to run scripts to automate Azure tasks.

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.

The current version of the Azure CLI isĀ 2.54.0.

Install Azure CLI on Windows


# Download and Install Interactive
Download Link - https://aka.ms/installazurecliwindowsx64

# Using Command line with Powershell
# To install the Azure CLI using PowerShell, start PowerShell as administrator and run the following command:

$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows -OutFile .\AzureCLI.msi; Start-Process msiexec.exe -Wait -ArgumentList '/I AzureCLI.msi /quiet'; Remove-Item .\AzureCLI.msi

# You can also use winget, Microsoft's Package manager for Windows, to install and manage updates for Azure CLI.
winget install -e --id Microsoft.AzureCLI

Install the Azure CLI on Linux


The CLI requires the following software:

Python 3.6.x, 3.7.x or 3.8.x.
libffi
OpenSSL 1.0.2

$ curl -L https://aka.ms/InstallAzureCli | bash

How to run the Azure CLI in a Docker container?


$ docker run -it mcr.microsoft.com/azure-cli

FAQ of Azure CLI

What advantage is there to using Azure CLI?You can manage multiple Azure resources concurrently from a flexible command-line. For example, create 50 Azure storage accounts, or update multiple user permissions through a script.
Where can I run the Azure CLI?The Azure CLI runs in Windows (Cmd or PowerShell), Linux, macOS, Docker containers, and Azure Cloud Shell. Using Azure Cloud Shell is the quickest way to get started.
Do I have to install the Azure CLI?Azure Cloud Shell and some Linux distributions have the Azure CLI preinstalled. For all other environments, you must install the Azure CLI.
How do I run the Azure CLI in a Docker container?docker run -it mcr.microsoft.com/azure-cli
What URLs do I need for proxy bypass?This depends on the Cloud you are using. For a complete list see the list of endpoints needed for proxy bypass.
How do I sign in?Use az login inside your console window. Use your own Azure username and password, a service principal, managed identity or WAM.

Using reference commands

QuestionAnswer
What is the Azure CLI syntax pattern?“command group + command subgroup + command + –parameters” Example: “az storage account create –name myStorageAccount”
What is the difference between a command group, cmdlet, command, alias, module, and reference?Good question! The Azure CLI only has command groups, reference commands, and user-defined aliases. You may be thinking of Azure PowerShell if you are looking for cmdlets and modules.
What is an extension and why does it have to be installed separately?Extensions are command group add-ins that are not shipped as part of the core Azure CLI. You are prompted to install an extension the first time you use it. Get a list of available extensions by running az extension list-available -output table.
How do I get a list of all commands, both core and extension?For a list of command groups, in your console type az and Enter. For a list of subgroups and commands, use the --help parameter. Example: az account --help or az account subscription --help outputs a command list for just the group or subgroup.
Does the Azure CLI have tab completion?Yes! When typing a command in PowerShell, press your Tab key. This feature is only available in PowerShell.
How do I get in-line help?Every command has a --help parameter that results in descriptions and tips to display in your console. Example: az account ---help or az vm create --help
How can I learn to use multiple reference commands to complete a single job to be done?We’re glad you asked! The Azure CLI provides several interactive commands that provide syntax and next steps. In the next section, learn about az interactiveaz scenarioaz next, and az find.

Learning Azure CLI

There are several reference commands that provide interactive prompts to help you learn the Azure CLI.

CommandDescriptionExample
az interactiveIn a PowerShell console, get auto-completion, command descriptions, and examples as you type.See Work in interactive mode for more information. Example: Type az interactive in your console window then Enter.
az scenarioGet end to end (E2E) examples and execute them with walk-through prompts.Type az scenario guide "keywords of interest" in your console then Enter. The Azure CLI returns scenarios based on your keyword(s). Example: az scenario guide "virtual machines"
az nextGet recommendations for the next Azure CLI command based on customer execution patterns. You are prompted to select a command path.Type az next in your console then Enter. Pick from 1 of 7 preset command paths.
az findThis is an AI robot that will return reference examples for keywords.Type az find "active subscription" in your console then Enter.

Common usage questions

QuestionReference command answer
How do I know what subscription I’m using?az account show --output table
How do I change my subscription?az account set --subscription "mySubscriptionName"
How can I set a default resource group and location?az config set defaults.location=westus2 defaults.group=MyResourceGroup
How do I query command output?az account show --query "{tenantId:tenantId,subscriptionid:id}"
How do I format output from a command?az account list --output table
Can you help me to learn Bash with Azure CLI commands?Absolutely! We all have different technical strengths, and for that reason, Microsoft offers a How-to guide for learning Bash. Enjoy!

Azure CLI Command Reference and Cheat Sheet

Get a list of resources without a tag

az resource list --query "[?tags == null].{Name:name, Type:type}" --output table

Get a list of resources with a specific tag

az resource list --query "[$tags.environment = 'development'].{Name:name, Type:type}" --output table

Get a list of resources without a specific tag and exclude resources with missing tags

az resource list --query "[?tags.environment != 'development' && not_null(tags)]"

Setting defaults

Set default resource group

az config set defaults.group=<resource-group>

Set default subscription

az account set --subscription <subscription>

Common Azure CLI Commands List

1) Manage resource groups and template deployments:

COMMANDS
az group createCreate a new resource group.
az group deleteDelete a resource group.
az group deploymentManage Azure Resource Manager deployments.
az group deployment cancelCancels a currently running template deployment.
az group deployment createStart a deployment.
az group deployment deleteDeletes a deployment from the deployment history.
az group deployment exportExport the template used for deployment.
az group deployment listGet all the deployments for a resource group.
az group deployment operationManage deployment operations.
az group deployment operation listGets all deployments operations for deployment.
az group deployment operation showGet a deploymentā€™s operation.
az group deployment showGets a deployment.
az group existsCheck if a resource group exists.
az group listList resource groups.
az group lockManage Azure resource group locks.
az group lock createCreate a resource group lock.
az group lock deleteDelete a resource group lock.
az group showGets a resource group.
az group updateUpdate a resource group.

2) Manage Linux or Windows virtual machines.

COMMANDS
az vm applicationManage applications for VM.
az vm application listList applications for VM.
az vm application setSet appliations for VM.
az vm assess-patchesAssess patches on a VM.
az vm auto-shutdownManage auto-shutdown for VM.
az vm availability-setGroup resources into availability sets.
az vm availability-set createCreate an Azure Availability Set.
az vm availability-set deleteDelete an availability set.
az vm availability-set listList availability sets.
az vm availability-set list-sizesList VM sizes for an availability set.
az vm availability-set showGet information for an availability set.
az vm availability-set updateUpdate an Azure Availability Set.
az vm captureCapture information for a stopped VM.
az vm convertConvert a VM with unmanaged disks to use managed disks.
az vm createCreate an Azure Virtual Machine.
az vm deallocateDeallocate a VM.
az vm deleteDelete a VM.
az vm diagnosticsConfigure the Azure Virtual Machine diagnostics extension.
az vm diskManage the managed data disks attached to a VM.
az vm disk attachAttach a managed persistent disk to a VM. Please note that ā€“ids only supports one disk.
az vm disk detachDetach a managed disk from a VM.
az vm encryptionManage encryption of VM disks.
az vm encryption showShow encryption status.
az vm extensionManage extensions on VMs.
az vm extension image list-versionsList the versions for available extensions.
az vm get-instance-viewGet instance information about a VM.
az vm hostManage Dedicated Hosts for Virtual Machines.
az vm host createCreate a dedicated host.
az vm host deleteDelete a dedicated host.
az vm identityManage service identities of a VM.
az vm identity assignEnable managed service identity on a VM.
az vm identity removeRemove managed service identities from a VM.
az vm identity showDisplay VMā€™s managed identity info.
az vm image list-skusList the VM image SKUs available in the Azure Marketplace.
az vm listList details of Virtual Machines.
az vm list-ip-addressesList IP addresses associated with a VM.
az vm list-sizesList available sizes for VMs.
az vm list-skusGet details for compute-related resource SKUs.
az vm list-usageList available usage resources for VMs.
az vm list-vm-resize-optionsList available resizing options for VMs.
az vm monitorManage monitor aspect for a vm.
az vm nicManage network interfaces. See also az network nic.
az vm nic addAdd existing NICs to a VM.
az vm nic listList the NICs available on a VM.
az vm open-portOpens a VM to inbound traffic on specified ports.
az vm redeployRedeploy an existing VM.
az vm repairAuto repair commands to fix VMs.
az vm resizeUpdate a VMā€™s size.
az vm restartRestart VMs.
az vm secretManage VM secrets.
az vm secret addAdd a secret to a VM.
az vm secret formatTransform secrets into a form that can be used by VMs and VMSSes.
az vm secret listList secrets on a VM.
az vm secret removeRemove a secret from a VM.
az vm startStart a stopped VM.
az vm stopPower off (stop) a running VM.
az vm updateUpdate the properties of a VM.
az vm userManage user accounts for a VM.
az vm user deleteDelete a user account from a VM.
az vm user reset-sshReset the SSH configuration on a VM.
az vm user updateUpdate a user account.
az vm waitPlace the CLI in a waiting state until a condition of the VM is met.

3) Manage storage accounts.

COMMANDS
az storage account check-nameCheck that the storage account name is valid and is not already in use.
az storage account createCreate a storage account.
az storage account deleteDelete a storage account.
az storage account encryption-scopeManage encryption scope for a storage account.
az storage account failoverFailover request can be triggered for a storage account in case of availability issues.
az storage account file-service-propertiesManage the properties of file service in storage account.
az storage account generate-sasGenerate a shared access signature for the storage account.
az storage account keysManage storage account keys.
az storage account listList storage accounts.
az storage account management-policyManage storage account management policies.
az storage account network-ruleManage network rules.
az storage account or-policyManage storage account Object Replication Policy.
az storage account or-policy createCreate Object Replication Service Policy for storage account.
az storage account or-policy deleteDelete specified Object Replication Service Policy associated with the specified storage account.
az storage account private-endpoint-connectionManage storage account private endpoint connection.
az storage account private-link-resourceManage storage account private link resources.
az storage account private-link-resource listGet the private link resources that need to be created for a storage account.
az storage account revoke-delegation-keysRevoke all user delegation keys for a storage account.
az storage account showShow storage account properties.
az storage account show-connection-stringGet the connection string for a storage account.

4) Manage KeyVault keys, secrets, and certificates.

COMMANDS
az keyvault backupManage full HSM backup.
az keyvault certificateManage certificates.
az keyvault certificate createCreate a Key Vault certificate.
az keyvault createCreate a Vault or HSM.
az keyvault deleteDelete a Vault or HSM.
az keyvault delete-policyDelete security policy settings for a Key Vault.
az keyvault keyManage keys.
az keyvault key backupRequest that a backup of the specified key be downloaded to the client.
az keyvault key createCreate a new key, stores it, then returns key parameters and attributes to the client.
az keyvault key decryptDecrypt a single block of encrypted data.
az keyvault key deleteDelete a key of any type from storage in Vault or HSM.
az keyvault key downloadDownload the public part of a stored key.
az keyvault key encryptEncrypt an arbitrary sequence of bytes using an encryption key that is stored in a Vault or HSM.
az keyvault key restoreRestore a backed up key to a Vault or HSM.
az keyvault key rotateRotate the key based on the key policy by generating a new version of the key.
az keyvault key rotation-policyManage keyā€™s rotation policy.
az keyvault key showGet a keyā€™s attributes and, if itā€™s an asymmetric key, its public material.
az keyvault key show-deletedGet the public part of a deleted key.
az keyvault listList Vaults and/or HSMs.
az keyvault list-deletedGet information about the deleted Vaults or HSMs in a subscription.
az keyvault network-ruleManage vault network ACLs.
az keyvault recoverRecover a Vault or HSM.
az keyvault restoreManage full HSM restore.
az keyvault restore startRestore a full backup of a HSM.
az keyvault roleManage user roles for access control.
az keyvault secretManage secrets.
az keyvault secret backupBacks up the specified secret.
az keyvault secret listList secrets in a specified key vault.
az keyvault secret showGet a specified secret from a given key vault.
az keyvault storageManage storage accounts.
az keyvault updateUpdate the properties of a Vault.

5) Manage SQL servers.

COMMANDS
az sql server createCreate a server.
az sql server deleteDeletes a server.
az sql server dns-aliasManage a serverā€™s DNS aliases.
az sql server firewall-ruleManage a serverā€™s firewall rules.
az sql server firewall-rule createCreate a firewall rule.
az sql server keyManage a serverā€™s keys.
az sql server key createCreates a server key.
az sql server key showShows a server key.
az sql server listList available servers.
az sql server list-usagesReturns server usages.
az sql server outbound-firewall-ruleManage a serverā€™s outbound firewall rules.
az sql server showGets a server.
az sql server vnet-ruleManage a serverā€™s virtual network rules.
az sql server vnet-rule createCreate a virtual network rule to allows access to an Azure SQL server.
az sql server vnet-rule deleteDeletes the virtual network rule with the given name.
az sql server vnet-rule listGets a list of virtual network rules in a server.

Reference

Rajesh Kumar
Follow me
Latest posts by Rajesh Kumar (see all)
Subscribe
Notify of
guest
1 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
Ravi
Ravi
5 months ago

Very informative blog, thanks for sharing it.

1
0
Would love your thoughts, please comment.x
()
x