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
Question | Answer |
---|---|
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 interactive , az scenario , az next , and az find . |
Learning Azure CLI
There are several reference commands that provide interactive prompts to help you learn the Azure CLI.
Command | Description | Example |
---|---|---|
az interactive | In 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 scenario | Get 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 next | Get 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 find | This is an AI robot that will return reference examples for keywords. | Type az find "active subscription" in your console then Enter. |
Common usage questions
Question | Reference 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 create | Create a new resource group. |
az group delete | Delete a resource group. |
az group deployment | Manage Azure Resource Manager deployments. |
az group deployment cancel | Cancels a currently running template deployment. |
az group deployment create | Start a deployment. |
az group deployment delete | Deletes a deployment from the deployment history. |
az group deployment export | Export the template used for deployment. |
az group deployment list | Get all the deployments for a resource group. |
az group deployment operation | Manage deployment operations. |
az group deployment operation list | Gets all deployments operations for deployment. |
az group deployment operation show | Get a deploymentās operation. |
az group deployment show | Gets a deployment. |
az group exists | Check if a resource group exists. |
az group list | List resource groups. |
az group lock | Manage Azure resource group locks. |
az group lock create | Create a resource group lock. |
az group lock delete | Delete a resource group lock. |
az group show | Gets a resource group. |
az group update | Update a resource group. |
2) Manage Linux or Windows virtual machines.
COMMANDS | |
az vm application | Manage applications for VM. |
az vm application list | List applications for VM. |
az vm application set | Set appliations for VM. |
az vm assess-patches | Assess patches on a VM. |
az vm auto-shutdown | Manage auto-shutdown for VM. |
az vm availability-set | Group resources into availability sets. |
az vm availability-set create | Create an Azure Availability Set. |
az vm availability-set delete | Delete an availability set. |
az vm availability-set list | List availability sets. |
az vm availability-set list-sizes | List VM sizes for an availability set. |
az vm availability-set show | Get information for an availability set. |
az vm availability-set update | Update an Azure Availability Set. |
az vm capture | Capture information for a stopped VM. |
az vm convert | Convert a VM with unmanaged disks to use managed disks. |
az vm create | Create an Azure Virtual Machine. |
az vm deallocate | Deallocate a VM. |
az vm delete | Delete a VM. |
az vm diagnostics | Configure the Azure Virtual Machine diagnostics extension. |
az vm disk | Manage the managed data disks attached to a VM. |
az vm disk attach | Attach a managed persistent disk to a VM. Please note that āids only supports one disk. |
az vm disk detach | Detach a managed disk from a VM. |
az vm encryption | Manage encryption of VM disks. |
az vm encryption show | Show encryption status. |
az vm extension | Manage extensions on VMs. |
az vm extension image list-versions | List the versions for available extensions. |
az vm get-instance-view | Get instance information about a VM. |
az vm host | Manage Dedicated Hosts for Virtual Machines. |
az vm host create | Create a dedicated host. |
az vm host delete | Delete a dedicated host. |
az vm identity | Manage service identities of a VM. |
az vm identity assign | Enable managed service identity on a VM. |
az vm identity remove | Remove managed service identities from a VM. |
az vm identity show | Display VMās managed identity info. |
az vm image list-skus | List the VM image SKUs available in the Azure Marketplace. |
az vm list | List details of Virtual Machines. |
az vm list-ip-addresses | List IP addresses associated with a VM. |
az vm list-sizes | List available sizes for VMs. |
az vm list-skus | Get details for compute-related resource SKUs. |
az vm list-usage | List available usage resources for VMs. |
az vm list-vm-resize-options | List available resizing options for VMs. |
az vm monitor | Manage monitor aspect for a vm. |
az vm nic | Manage network interfaces. See also az network nic. |
az vm nic add | Add existing NICs to a VM. |
az vm nic list | List the NICs available on a VM. |
az vm open-port | Opens a VM to inbound traffic on specified ports. |
az vm redeploy | Redeploy an existing VM. |
az vm repair | Auto repair commands to fix VMs. |
az vm resize | Update a VMās size. |
az vm restart | Restart VMs. |
az vm secret | Manage VM secrets. |
az vm secret add | Add a secret to a VM. |
az vm secret format | Transform secrets into a form that can be used by VMs and VMSSes. |
az vm secret list | List secrets on a VM. |
az vm secret remove | Remove a secret from a VM. |
az vm start | Start a stopped VM. |
az vm stop | Power off (stop) a running VM. |
az vm update | Update the properties of a VM. |
az vm user | Manage user accounts for a VM. |
az vm user delete | Delete a user account from a VM. |
az vm user reset-ssh | Reset the SSH configuration on a VM. |
az vm user update | Update a user account. |
az vm wait | Place the CLI in a waiting state until a condition of the VM is met. |
3) Manage storage accounts.
COMMANDS | |
az storage account check-name | Check that the storage account name is valid and is not already in use. |
az storage account create | Create a storage account. |
az storage account delete | Delete a storage account. |
az storage account encryption-scope | Manage encryption scope for a storage account. |
az storage account failover | Failover request can be triggered for a storage account in case of availability issues. |
az storage account file-service-properties | Manage the properties of file service in storage account. |
az storage account generate-sas | Generate a shared access signature for the storage account. |
az storage account keys | Manage storage account keys. |
az storage account list | List storage accounts. |
az storage account management-policy | Manage storage account management policies. |
az storage account network-rule | Manage network rules. |
az storage account or-policy | Manage storage account Object Replication Policy. |
az storage account or-policy create | Create Object Replication Service Policy for storage account. |
az storage account or-policy delete | Delete specified Object Replication Service Policy associated with the specified storage account. |
az storage account private-endpoint-connection | Manage storage account private endpoint connection. |
az storage account private-link-resource | Manage storage account private link resources. |
az storage account private-link-resource list | Get the private link resources that need to be created for a storage account. |
az storage account revoke-delegation-keys | Revoke all user delegation keys for a storage account. |
az storage account show | Show storage account properties. |
az storage account show-connection-string | Get the connection string for a storage account. |
4) Manage KeyVault keys, secrets, and certificates.
COMMANDS | |
az keyvault backup | Manage full HSM backup. |
az keyvault certificate | Manage certificates. |
az keyvault certificate create | Create a Key Vault certificate. |
az keyvault create | Create a Vault or HSM. |
az keyvault delete | Delete a Vault or HSM. |
az keyvault delete-policy | Delete security policy settings for a Key Vault. |
az keyvault key | Manage keys. |
az keyvault key backup | Request that a backup of the specified key be downloaded to the client. |
az keyvault key create | Create a new key, stores it, then returns key parameters and attributes to the client. |
az keyvault key decrypt | Decrypt a single block of encrypted data. |
az keyvault key delete | Delete a key of any type from storage in Vault or HSM. |
az keyvault key download | Download the public part of a stored key. |
az keyvault key encrypt | Encrypt an arbitrary sequence of bytes using an encryption key that is stored in a Vault or HSM. |
az keyvault key restore | Restore a backed up key to a Vault or HSM. |
az keyvault key rotate | Rotate the key based on the key policy by generating a new version of the key. |
az keyvault key rotation-policy | Manage keyās rotation policy. |
az keyvault key show | Get a keyās attributes and, if itās an asymmetric key, its public material. |
az keyvault key show-deleted | Get the public part of a deleted key. |
az keyvault list | List Vaults and/or HSMs. |
az keyvault list-deleted | Get information about the deleted Vaults or HSMs in a subscription. |
az keyvault network-rule | Manage vault network ACLs. |
az keyvault recover | Recover a Vault or HSM. |
az keyvault restore | Manage full HSM restore. |
az keyvault restore start | Restore a full backup of a HSM. |
az keyvault role | Manage user roles for access control. |
az keyvault secret | Manage secrets. |
az keyvault secret backup | Backs up the specified secret. |
az keyvault secret list | List secrets in a specified key vault. |
az keyvault secret show | Get a specified secret from a given key vault. |
az keyvault storage | Manage storage accounts. |
az keyvault update | Update the properties of a Vault. |
5) Manage SQL servers.
COMMANDS | |
az sql server create | Create a server. |
az sql server delete | Deletes a server. |
az sql server dns-alias | Manage a serverās DNS aliases. |
az sql server firewall-rule | Manage a serverās firewall rules. |
az sql server firewall-rule create | Create a firewall rule. |
az sql server key | Manage a serverās keys. |
az sql server key create | Creates a server key. |
az sql server key show | Shows a server key. |
az sql server list | List available servers. |
az sql server list-usages | Returns server usages. |
az sql server outbound-firewall-rule | Manage a serverās outbound firewall rules. |
az sql server show | Gets a server. |
az sql server vnet-rule | Manage a serverās virtual network rules. |
az sql server vnet-rule create | Create a virtual network rule to allows access to an Azure SQL server. |
az sql server vnet-rule delete | Deletes the virtual network rule with the given name. |
az sql server vnet-rule list | Gets a list of virtual network rules in a server. |
Reference
- Best AI tools for Software Engineers - November 4, 2024
- Installing Jupyter: Get up and running on your computer - November 2, 2024
- An Introduction of SymOps by SymOps.com - October 30, 2024
Very informative blog, thanks for sharing it.