Azure Compute CLI Reference
The Azure CLI is a powerful tool for managing Azure resources from your command line. This documentation provides a comprehensive reference for compute-related commands, enabling you to automate deployments, configure resources, and monitor your cloud infrastructure.
Prerequisites: Ensure you have the Azure CLI installed and are logged into your Azure account using
az login.
Virtual Machines (VM) Management
Commands for creating, managing, and deleting Azure Virtual Machines.
Creating a VM
The following command creates a simple Ubuntu Linux VM in a new resource group.
az vm create \
--resource-group MyResourceGroup \
--name MyVM \
--image UbuntuLTS \
--admin-username azureuser \
--generate-ssh-keys
Listing VMs
az vm list \
--resource-group MyResourceGroup \
--output table
Starting/Stopping a VM
az vm start --resource-group MyResourceGroup --name MyVM
az vm stop --resource-group MyResourceGroup --name MyVM
Deleting a VM
az vm delete --resource-group MyResourceGroup --name MyVM --yes
Virtual Machine Scale Sets (VMSS) Management
Manage groups of identical VMs that can be automatically scaled.
Creating a VMSS
az vmss create \
--resource-group MyResourceGroup \
--name MyVMSS \
--image UbuntuLTS \
--vm-sku Standard_DS1_v2 \
--instance-count 3 \
--upgrade-policy-mode automatic
Scaling a VMSS
az vmss scale \
--resource-group MyResourceGroup \
--name MyVMSS \
--new-capacity 5
Azure Kubernetes Service (AKS) Management
Deploy and manage Kubernetes clusters on Azure.
Creating an AKS cluster
az aks create \
--resource-group MyResourceGroup \
--name MyAKSCluster \
--node-count 1 \
--enable-addons monitoring \
--generate-ssh-keys
Getting AKS credentials
az aks get-credentials --resource-group MyResourceGroup --name MyAKSCluster
Managed Disks
Create, attach, and manage Azure Managed Disks.
Creating a Managed Disk
az disk create \
--resource-group MyResourceGroup \
--name MyDisk \
--size-gb 128 \
--sku Standard_LRS
Attaching a Disk to a VM
az vm disk attach \
--resource-group MyResourceGroup \
--vm-name MyVM \
--name MyDisk
Snapshots
Create and manage disk snapshots for backup and disaster recovery.
Creating a Snapshot
az snapshot create \
--resource-group MyResourceGroup \
--name MySnapshot \
--source MyDisk
Listing Snapshots
az snapshot list \
--resource-group MyResourceGroup \
--output table
Tip: Use the
--output parameter with values like table, json, or yaml for different display formats.