Delen via


Common Azure CLI commands for managing Azure resources

Van toepassing op: ✔️ Linux-VM's ✔️ Windows-VM's ✔️ Flexibele schaalsets

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).

Voor dit artikel is Azure CLI versie 2.0.4 of hoger vereist. Voer az --version uit om de versie te vinden. 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.

Virtuele machines maken

Opdracht Azure CLI-opdrachten
Een brongroep maken az group create --name myResourceGroup --location eastus
Een Virtuele Linux-machine maken az vm create --resource-group myResourceGroup --name myVM --image LinuxImageName
Een Windows-VM maken az vm create --resource-group myResourceGroup --name myVM --image win2016datacenter

Manage VM state

Opdracht Azure CLI-opdrachten
Een VM starten az vm start --resource-group myResourceGroup --name myVM
Een VM stoppen az vm stop --resource-group myResourceGroup --name myVM
Deallocate a VM az vm deallocate --resource-group myResourceGroup --name myVM
Een virtuele machine opnieuw opstarten az vm restart --resource-group myResourceGroup --name myVM
Een VM opnieuw implementeren az vm redeploy --resource-group myResourceGroup --name myVM
Een virtuele machine verwijderen az vm delete --resource-group myResourceGroup --name myVM

Get VM info

Opdracht Azure CLI-opdrachten
List VMs az vm list
Informatie over een VM ophalen az vm show --resource-group myResourceGroup --name myVM
Get usage of VM resources az vm list-usage --location eastus
Get all available VM sizes az vm list-sizes --location eastus

Schijven en schijfkopieën

Opdracht Azure CLI-opdrachten
Een gegevensschijf toevoegen aan een virtuele machine 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"
Een gegevensschijf verwijderen uit een virtuele machine 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
Snapshot a 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

Volgende stappen

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