Azure CLI Commands
Introduction
The Azure command-line interface (Azure CLI) is a set of commands used to create and manage Azure resources.
Installing Azure CLI
Use the following commands to install Azure CLI in Windows, MacOS and Linux environments.
# MacOS (using Homebrew):
brew install azure-cli
# Windows OS (using choco)
choco install azure-cli
# verify the installation by running
az --version
# updating cli
az upgrade
For more information, refer to the official documentation: - How to install the Azure CLI
az login
az account
az account set -s "azure-cloud"
# Get a list of subscriptions for the logged in account.
az account list -o table
# To view all the Azure subscription names and IDs for a specific Microsoft account,
az account list --query "[?user.name=='testuser@example.com'].{Name:name, ID:id, Default:isDefault}" --output Table
# Get the details of a subscription.
az account show
az account show -o table
# Get all subscriptions for a tenant.
az account subscription list -o table
# Get details about a specified subscription.
az account subscription show --subscription-id "85c49b84-b13d-4168-962c-8107c5b32b7e"
# or
az account subscription show --id '85c49b84-b13d-4168-962c-8107c5b32b7e'
# Get the tenants for your account.
az account tenant list
az group
# Create a new resource group.k
az group create -l 'eastus' -n 'rg-demo'
# List resource groups.
az group list -o table
# Check if a resource group exists.
az group exists -n 'rg-demo'
# Create a resource group lock.
az group lock create --lock-type ReadOnly -n lockName -g 'rg-demo'
az group lock create --lock-type CanNotDelete -n lockName -g 'rg-demo'
# List lock information in the resource-group.
az group lock list -g 'rg-demo'
# Show the details of a resource group lock.
az group lock show -n lockname -g 'rg-demo'
# Delete a resource group lock.
az group lock delete -n lockName -g 'rg-demo'
# Delete a resource group.
az group delete -n 'rg-demo'
az mysql
az mysql db list --resource-group --server-name
az mysql db list -g testgroup -s testsvr
az mysql db show -g testgroup -s testsvr -n testdb
az storage
# List blobs in a given container.
az storage blob list -c mycontainer --prefix foo
# Get the details of a blob.
az storage blob show -c mycontainer -n MyBlob
# Copy a blob asynchronously. Use az storage blob show to check the status of the blobs.
az storage blob copy start --account-key 00000000 --account-name MyAccount --destination-blob MyDestinationBlob --destination-container MyDestinationContainer --source-uri https://storage.blob.core.windows.net/photos
az aks
Manage Azure Kubernetes Services - Reference
# List managed Kubernetes clusters.
az aks list -o table
# Get access credentials for a managed Kubernetes cluster.
# user authentication
az aks get-credentials --name 'aks-cluster1-dev' --resource-group 'rg-aks-dev'
# admin authentication
az aks get-credentials --name 'aks-cluster1-dev' --resource-group 'rg-aks-dev' --admin
# Get the versions available for creating a managed Kubernetes cluster.
az aks get-versions --location westus2 -o table
# Run a shell command
az aks command invoke -n 'aks-cluster1-dev' -g 'rg-aks-dev' --command "kubectl get namespaces"
az aks command invoke -n 'aks-cluster1-dev' -g 'rg-aks-dev' --command "kubectl create namespace test"
# Download and install kubectl, the Kubernetes command-line tool.
az aks install-cli
# List node pools in the managed Kubernetes cluster
az aks nodepool list --cluster-name 'aks-cluster1-dev' -g 'rg-aks-dev'
az aks nodepool list --cluster-name 'aks-cluster1-dev' -g 'rg-aks-dev' -o table
az acr
Manage private registries with Azure Container Registries. - Reference
az ad
Azure AD for Role Based Access Control - Reference
az webapp
Manage web app logs - Reference
# Start live log tracing for a web app.
az webapp log tail --name 'feedback-api-app' --resource-group 'test-rg-dev'
# Download a web app's log history as a zip file.
az webapp log download --name 'feedback-api-app' --resource-group 'test-rg-dev' --log-file webapp_303029911.zip