Dela via


Common Azure CLI commands for managing Azure resources

Gäller för: ✔️ Virtuella Linux-datorer ✔️ Virtuella Windows-datorer ✔️ Flexibla skalningsuppsättningar

The Azure CLI allows you to create and manage your Azure resources on macOS, Linux, and Windows. This article details some of the most common commands to create and manage virtual machines (VMs).

This article requires the Azure CLI version 2.0.4 or later. Kör az --version för att hitta versionen. If you need to upgrade, see Install Azure CLI. You can also use Cloud Shell from your browser.

Basic Azure Resource Manager commands in Azure CLI

For more detailed help with specific command line switches and options, you can use the online command help and options by typing az <command> <subcommand> --help.

Skapa VM:ar

Uppgift Azure CLI-kommandon
Skapa en resursgrupp az group create --name myResourceGroup --location eastus
Skapa en virtuell Linux-dator az vm create --resource-group myResourceGroup --name myVM --image LinuxImageName
Skapa en virtuell Windows-dator az vm create --resource-group myResourceGroup --name myVM --image win2016datacenter

Manage VM state

Uppgift Azure CLI-kommandon
Start a VM az vm start --resource-group myResourceGroup --name myVM
Stop a VM az vm stop --resource-group myResourceGroup --name myVM
Deallocate a VM az vm deallocate --resource-group myResourceGroup --name myVM
Restart a VM az vm restart --resource-group myResourceGroup --name myVM
Återdistribuera en VM az vm redeploy --resource-group myResourceGroup --name myVM
Delete a VM az vm delete --resource-group myResourceGroup --name myVM

Get VM info

Uppgift Azure CLI-kommandon
List VMs az vm list
Hämta information om en virtuell dator az vm show --resource-group myResourceGroup --name myVM
Get usage of VM resources az vm list-usage --location eastus
Hämta alla tillgängliga VM-storlekar az vm list-sizes --location eastus

Disks and images

Uppgift Azure CLI-kommandon
Lägga till en datadisk till en virtuell dator az vm disk attach --resource-group myResourceGroup --vm-name myVM --disk myDataDisk --size-gb 128 --new
List attached disks to a VM az vm show --resource-group groupName --name vmName --query "storageProfile"
Ta bort en datadisk från en virtuell dator az vm disk detach --resource-group myResourceGroup --vm-name myVM --disk myDataDisk
Resize a disk az disk update --resource-group myResourceGroup --name myDataDisk --size-gb 256
Ögonblicksbild av en disk az snapshot create --resource-group myResourceGroup --name mySnapshot --source myDataDisk
Create image of a VM az image create --resource-group myResourceGroup --source myVM --name myImage
Create VM from image az vm create --resource-group myResourceGroup --name myNewVM --image myImage

Nästa steg

For additional examples of the CLI commands, see the Create and Manage Linux VMs with the Azure CLI tutorial.