您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

az vm

Manage Linux or Windows virtual machines.

Commands

az vm availability-set Group resources into availability sets.
az vm availability-set convert Convert an Azure Availability Set to contain VMs with managed disks.
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 boot-diagnostics Troubleshoot the startup of an Azure Virtual Machine.
az vm boot-diagnostics disable Disable the boot diagnostics on a VM.
az vm boot-diagnostics enable Enable the boot diagnostics on a VM.
az vm boot-diagnostics get-boot-log Get the boot diagnostics log from a VM.
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 diagnostics get-default-config Get the default configuration settings for a VM.
az vm diagnostics set Configure the Azure VM 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.
az vm disk detach Detach a managed disk from a VM.
az vm encryption Manage encryption of VM disks.
az vm encryption disable Disable disk encryption on the OS disk and/or data disks. Decrypt mounted disks.
az vm encryption enable Enable disk encryption on the OS disk and/or data disks. Encrypt mounted disks.
az vm encryption show Show encryption status.
az vm extension Manage extensions on VMs.
az vm extension delete Remove an extension attached to a VM.
az vm extension image Find the available VM extensions for a subscription and region.
az vm extension image list List the information on available extensions.
az vm extension image list-names List the names of available extensions.
az vm extension image list-versions List the versions for available extensions.
az vm extension image show Display information for an extension.
az vm extension list List the extensions attached to a VM.
az vm extension set Set extensions for a VM.
az vm extension show Display information about extensions attached to a VM.
az vm extension wait Place the CLI in a waiting state until a condition of a virtual machine extension is met.
az vm generalize Mark a VM as generalized, allowing it to be imaged for multiple deployments.
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 host get-instance-view Get instance information about a dedicated host.
az vm host group Manage Dedicated Host Groups.
az vm host group create Create a dedicated host group.
az vm host group delete Delete a dedicated host group.
az vm host group list List dedicated host groups.
az vm host group show Get the details of a dedicated host group.
az vm host group update Update a dedicated host group.
az vm host list List dedicated hosts.
az vm host show Get the details of a dedicated host.
az vm host update Update 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 Information on available virtual machine images.
az vm image accept-terms Accept Azure Marketplace term so that the image can be used to create VMs.
az vm image list List the VM/VMSS images available in the Azure Marketplace.
az vm image list-offers List the VM image offers available in the Azure Marketplace.
az vm image list-publishers List the VM image publishers available in the Azure Marketplace.
az vm image list-skus List the VM image SKUs available in the Azure Marketplace.
az vm image show Get the details for a VM image available in the Azure Marketplace.
az vm image terms Manage Azure Marketplace image terms.
az vm image terms accept Accept Azure Marketplace image terms so that the image can be used to create VMs.
az vm image terms cancel Cancel Azure Marketplace image terms.
az vm image terms show Get the details of Azure Marketplace image terms.
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 monitor log Manage log analytics workspace for a vm.
az vm monitor log show Executes a query against the Log Analytics workspace linked with 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 nic remove Remove NICs from a VM.
az vm nic set Configure settings of a NIC attached to a VM.
az vm nic show Display information for a NIC attached to a VM.
az vm open-port Opens a VM to inbound traffic on specified ports.
az vm perform-maintenance The operation to perform maintenance on a virtual machine.
az vm redeploy Redeploy an existing VM.
az vm resize Update a VM's size.
az vm restart Restart VMs.
az vm run-command Manage run commands on a Virtual Machine.
az vm run-command invoke Execute a specific run command on a vm.
az vm run-command list Lists all available run commands for a subscription in a location.
az vm run-command show Gets specific run command for a subscription in a location.
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 show Get the details of a VM.
az vm start Start a stopped VM.
az vm stop Power off (stop) a running VM.
az vm unmanaged-disk Manage the unmanaged data disks attached to a VM.
az vm unmanaged-disk attach Attach an unmanaged persistent disk to a VM.
az vm unmanaged-disk detach Detach an unmanaged disk from a VM.
az vm unmanaged-disk list List unmanaged disks of a 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.

az vm capture

Capture information for a stopped VM.

az vm capture --vhd-name-prefix
[--ids]
[--name]
[--overwrite]
[--resource-group]
[--storage-container]
[--subscription]

Examples

Deallocate, generalize, and capture a stopped virtual machine.

az vm deallocate -g MyResourceGroup -n MyVm
az vm generalize -g MyResourceGroup -n MyVm
az vm capture -g MyResourceGroup -n MyVm --vhd-name-prefix MyPrefix

Deallocate, generalize, and capture multiple stopped virtual machines.

vms_ids=$(az vm list -g MyResourceGroup --query "[].id" -o tsv)
az vm deallocate --ids {vms_ids}
az vm generalize --ids {vms_ids}
az vm capture --ids {vms_ids} --vhd-name-prefix MyPrefix

Required Parameters

--vhd-name-prefix

The VHD name prefix specify for the VM disks.

Optional Parameters

--ids

One or more resource IDs (space-delimited). It should be a complete resource ID containing all information of 'Resource Id' arguments. If provided, no other 'Resource Id' arguments should be specified.

--name -n

The name of the Virtual Machine. You can configure the default using az configure --defaults vm=<name>.

--overwrite

Overwrite the existing disk file.

default value: 1
--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--storage-container

The storage account container name in which to save the disks.

default value: vhds
--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

az vm convert

Convert a VM with unmanaged disks to use managed disks.

az vm convert [--ids]
[--name]
[--resource-group]
[--subscription]

Examples

Convert a VM with unmanaged disks to use managed disks.

az vm convert -g MyResourceGroup -n MyVm

Convert all VMs with unmanaged disks in a resource group to use managed disks.

az vm convert --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv)

Optional Parameters

--ids

One or more resource IDs (space-delimited). It should be a complete resource ID containing all information of 'Resource Id' arguments. If provided, no other 'Resource Id' arguments should be specified.

--name -n

The name of the Virtual Machine. You can configure the default using az configure --defaults vm=<name>.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

az vm create

Create an Azure Virtual Machine.

az vm create --name
--resource-group
[--accelerated-networking {false, true}]
[--admin-password]
[--admin-username]
[--asgs]
[--assign-identity]
[--attach-data-disks]
[--attach-os-disk]
[--authentication-type {all, password, ssh}]
[--availability-set]
[--boot-diagnostics-storage]
[--computer-name]
[--custom-data]
[--data-disk-caching]
[--data-disk-sizes-gb]
[--enable-agent {false, true}]
[--ephemeral-os-disk {false, true}]
[--eviction-policy {Deallocate, Delete}]
[--generate-ssh-keys]
[--host]
[--host-group]
[--image]
[--license-type {None, Windows_Client, Windows_Server}]
[--location]
[--max-price]
[--nics]
[--no-wait]
[--nsg]
[--nsg-rule {RDP, SSH}]
[--os-disk-caching {None, ReadOnly, ReadWrite}]
[--os-disk-name]
[--os-disk-size-gb]
[--os-type {linux, windows}]
[--plan-name]
[--plan-product]
[--plan-promotion-code]
[--plan-publisher]
[--ppg]
[--priority {Low, Regular, Spot}]
[--private-ip-address]
[--public-ip-address]
[--public-ip-address-allocation {dynamic, static}]
[--public-ip-address-dns-name]
[--public-ip-sku {Basic, Standard}]
[--role]
[--scope]
[--secrets]
[--size]
[--ssh-dest-key-path]
[--ssh-key-values]
[--storage-account]
[--storage-container-name]
[--storage-sku]
[--subnet]
[--subnet-address-prefix]
[--subscription]
[--tags]
[--ultra-ssd-enabled {false, true}]
[--use-unmanaged-disk]
[--validate]
[--vmss]
[--vnet-address-prefix]
[--vnet-name]
[--workspace]
[--zone {1, 2, 3}]

Examples

Create a default Ubuntu VM with automatic SSH authentication.

az vm create -n MyVm -g MyResourceGroup --image UbuntuLTS

Create a default RedHat VM with automatic SSH authentication using an image URN.

az vm create -n MyVm -g MyResourceGroup --image RedHat:RHEL:7-RAW:7.4.2018010506

Create a default Windows Server VM with a private IP address.

az vm create -n MyVm -g MyResourceGroup --public-ip-address "" --image Win2012R2Datacenter

Create a VM from a custom managed image.

az vm create -g MyResourceGroup -n MyVm --image MyImage

Create a VM by attaching to a managed operating system disk.

az vm create -g MyResourceGroup -n MyVm --attach-os-disk MyOsDisk --os-type linux

Create an Ubuntu Linux VM using a cloud-init script for configuration. See: https://docs.microsoft.com/azure/virtual-machines/virtual-machines-linux-using-cloud-init.

az vm create -g MyResourceGroup -n MyVm --image debian --custom-data MyCloudInitScript.yml

Create a Debian VM with SSH key authentication and a public DNS entry, located on an existing virtual network and availability set.

az vm create -n MyVm -g MyResourceGroup --image debian --vnet-name MyVnet --subnet subnet1 \
    --availability-set MyAvailabilitySet --public-ip-address-dns-name MyUniqueDnsName \
    --ssh-key-value @key-file

Create a simple Ubuntu Linux VM with a public IP address, DNS entry, two data disks (10GB and 20GB), and then generate ssh key pairs.

az vm create -n MyVm -g MyResourceGroup --public-ip-address-dns-name MyUniqueDnsName \
    --image ubuntults --data-disk-sizes-gb 10 20 --size Standard_DS2_v2 \
    --generate-ssh-keys

Create a Debian VM using Key Vault secrets.

az keyvault certificate create --vault-name vaultname -n cert1 \
  -p "$(az keyvault certificate get-default-policy)"

secrets=$(az keyvault secret list-versions --vault-name vaultname \
  -n cert1 --query "[?attributes.enabled].id" -o tsv)

vm_secrets=$(az vm secret format -s "$secrets")

az vm create -g group-name -n vm-name --admin-username deploy  \
  --image debian --secrets "$vm_secrets"

Create a CentOS VM with a system assigned identity. The VM will have a 'Contributor' role with access to a storage account.

az vm create -n MyVm -g rg1 --image centos --assign-identity --scope /subscriptions/99999999-1bf0-4dda-aec3-cb9272f09590/MyResourceGroup/myRG/providers/Microsoft.Storage/storageAccounts/storage1

Create a debian VM with a user assigned identity.

az vm create -n MyVm -g rg1 --image debian --assign-identity  /subscriptions/99999999-1bf0-4dda-aec3-cb9272f09590/resourcegroups/myRG/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myID

Create a debian VM with both system and user assigned identity.

az vm create -n MyVm -g rg1 --image debian --assign-identity  [system] /subscriptions/99999999-1bf0-4dda-aec3-cb9272f09590/resourcegroups/myRG/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myID

Create a VM in an availability zone in the current resource group's region

az vm create -n MyVm -g MyResourceGroup --image Centos --zone 1

Required Parameters

--name -n

Name of the virtual machine.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

Optional Parameters

--accelerated-networking

Enable accelerated networking. Unless specified, CLI will enable it based on machine image and size.

accepted values: false, true
--admin-password

Password for the VM if authentication type is 'Password'.

--admin-username

Username for the VM.

default value: your_system_user_login_name
--asgs

Space-separated list of existing application security groups to associate with the VM.

--assign-identity

Accept system or user assigned identities separated by spaces. Use '[system]' to refer system assigned identity, or a resource id to refer user assigned identity. Check out help for more examples.

--attach-data-disks

Attach existing data disks to the VM. Can use the name or ID of a managed disk or the URI to an unmanaged disk VHD.

--attach-os-disk

Attach an existing OS disk to the VM. Can use the name or ID of a managed disk or the URI to an unmanaged disk VHD.

--authentication-type

Type of authentication to use with the VM. Defaults to password for Windows and SSH public key for Linux. "all" enables both ssh and password authentication.

accepted values: all, password, ssh
--availability-set

Name or ID of an existing availability set to add the VM to. None by default.

--boot-diagnostics-storage

Pre-existing storage account name or its blob uri to capture boot diagnostics. Its sku should be one of Standard_GRS, Standard_LRS and Standard_RAGRS.

--computer-name

The host OS name of the virtual machine. Defaults to the name of the VM.

--custom-data

Custom init script file or text (cloud-init, cloud-config, etc..).

--data-disk-caching

Storage caching type for data disk(s), including 'None', 'ReadOnly', 'ReadWrite', etc. Use a singular value to apply on all disks, or use '= =' to configure individual disk.

--data-disk-sizes-gb

Space-separated empty managed data disk sizes in GB to create.

--enable-agent

Indicates whether virtual machine agent should be provisioned on the virtual machine. When this property is not specified, default behavior is to set it to true. This will ensure that VM Agent is installed on the VM so that extensions can be added to the VM later.

accepted values: false, true
--ephemeral-os-disk

Allows you to create an OS disk directly on the host node, providing local disk performance and faster VM/VMSS reimage time.

accepted values: false, true
--eviction-policy

The eviction policy for the low priority virtual machine.

accepted values: Deallocate, Delete
--generate-ssh-keys

Generate SSH public and private key files if missing. The keys will be stored in the ~/.ssh directory.

--host

Name or ID of the dedicated host this VM will reside in. If a name is specified, a host group must be specified via --host-group.

--host-group

Name of the dedicated host group containing the dedicated host this VM will reside in.

--image

The name of the operating system image as a URN alias, URN, custom image name or ID, or VHD blob URI. This parameter is required unless using --attach-os-disk. Valid URN format: "Publisher:Offer:Sku:Version".

value from: az vm image list, az vm image show
--license-type

Specifies that the Windows image or disk was licensed on-premises. To enable Azure Hybrid Benefit for Windows Server, use 'Windows_Server'. To enable Multitenant Hosting Rights for Windows 10, use 'Windows_Client'. For more information see the Azure Windows VM online docs.

accepted values: None, Windows_Client, Windows_Server
--location -l

Location in which to create VM and related resources. If default location is not configured, will default to the resource group's location.

--max-price

The maximum price (in US Dollars) you are willing to pay for a low priority VM/VMSS. -1 indicates that the low priority VM/VMSS should not be evicted for price reasons.

--nics

Names or IDs of existing NICs to attach to the VM. The first NIC will be designated as primary. If omitted, a new NIC will be created. If an existing NIC is specified, do not specify subnet, VNet, public IP or NSG.

--no-wait

Do not wait for the long-running operation to finish.

--nsg

The name to use when creating a new Network Security Group (default) or referencing an existing one. Can also reference an existing NSG by ID or specify "" for none.

--nsg-rule

NSG rule to create when creating a new NSG. Defaults to open ports for allowing RDP on Windows and allowing SSH on Linux.

accepted values: RDP, SSH
--os-disk-caching

Storage caching type for the VM OS disk. Default: ReadWrite.

accepted values: None, ReadOnly, ReadWrite
--os-disk-name

The name of the new VM OS disk.

--os-disk-size-gb

The size of the os disk in GB.

--os-type

Type of OS installed on a custom VHD. Do not use when specifying an URN or URN alias.

accepted values: linux, windows
--plan-name

Plan name.

--plan-product

Plan product.

--plan-promotion-code

Plan promotion code.

--plan-publisher

Plan publisher.

--ppg

The name or ID of the proximity placement group the VM should be associated with.

--priority

Priority. Use 'Low' to run short-lived workloads in a cost-effective way.

accepted values: Low, Regular, Spot
--private-ip-address

Static private IP address (e.g. 10.0.0.5).

--public-ip-address

Name of the public IP address when creating one (default) or referencing an existing one. Can also reference an existing public IP by ID or specify "" for None.

--public-ip-address-allocation
accepted values: dynamic, static
--public-ip-address-dns-name

Globally unique DNS name for a newly created public IP.

--public-ip-sku

Public IP SKU. It is set to Basic by default.

accepted values: Basic, Standard
--role

Role name or id the system assigned identity will have.

default value: Contributor
--scope

Scope that the system assigned identity can access.

--secrets

One or many Key Vault secrets as JSON strings or files via @{path} containing [{ "sourceVault": { "id": "value" }, "vaultCertificates": [{ "certificateUrl": "value", "certificateStore": "cert store name (only on windows)"}] }].

--size

The VM size to be created. See https://azure.microsoft.com/pricing/details/virtual-machines/ for size info.

default value: Standard_DS1_v2
value from: az vm list-sizes
--ssh-dest-key-path

Destination file path on the VM for the SSH key. If the file already exists, the specified key(s) are appended to the file.

--ssh-key-values

Space-separated list of SSH public keys or public key file paths.

--storage-account

Only applicable when used with --use-unmanaged-disk. The name to use when creating a new storage account or referencing an existing one. If omitted, an appropriate storage account in the same resource group and location will be used, or a new one will be created.

--storage-container-name

Only applicable when used with --use-unmanaged-disk. Name of the storage container for the VM OS disk. Default: vhds.

--storage-sku

The SKU of the storage account with which to persist VM. Use a singular sku that would be applied across all disks, or specify individual disks. Usage: [--storage-sku SKU | --storage-sku ID=SKU ID=SKU ID=SKU...], where each ID is "os" or a 0-indexed lun. Allowed values: Standard_LRS, Premium_LRS, StandardSSD_LRS, UltraSSD_LRS.

--subnet

The name of the subnet when creating a new VNet or referencing an existing one. Can also reference an existing subnet by ID. If omitted, an appropriate VNet and subnet will be selected automatically, or a new one will be created.

--subnet-address-prefix

The subnet IP address prefix to use when creating a new VNet in CIDR format.

default value: 10.0.0.0/24
--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

--tags

Space-separated tags in 'key[=value]' format. Use "" to clear existing tags.

--ultra-ssd-enabled

Enables or disables the capability to have 1 or more managed data disks with UltraSSD_LRS storage account.

accepted values: false, true
--use-unmanaged-disk

Do not use managed disk to persist VM.

--validate

Generate and validate the ARM template without creating any resources.

--vmss

Name or ID of an existing virtual machine scale set that the virtual machine should be assigned to. None by default.

--vnet-address-prefix

The IP address prefix to use when creating a new VNet in CIDR format.

default value: 10.0.0.0/16
--vnet-name

Name of the virtual network when creating a new one or referencing an existing one.

--workspace

Name or ID of Log Analytics Workspace. If you specify the workspace through its name, the workspace should be in the same resource group with the vm, otherwise a new workspace will be created.

--zone -z

Availability zone into which to provision the resource.

accepted values: 1, 2, 3

az vm deallocate

Deallocate a VM.

az vm deallocate [--ids]
[--name]
[--no-wait]
[--resource-group]
[--subscription]

Examples

Deallocate, generalize, and capture a stopped virtual machine.

az vm deallocate -g MyResourceGroup -n MyVm
az vm generalize -g MyResourceGroup -n MyVm
az vm capture -g MyResourceGroup -n MyVm --vhd-name-prefix MyPrefix

Deallocate, generalize, and capture multiple stopped virtual machines.

vms_ids=$(az vm list -g MyResourceGroup --query "[].id" -o tsv)
az vm deallocate --ids {vms_ids}
az vm generalize --ids {vms_ids}
az vm capture --ids {vms_ids} --vhd-name-prefix MyPrefix

Deallocate a VM. (autogenerated)

az vm deallocate --name MyVm --no-wait --resource-group MyResourceGroup

Optional Parameters

--ids

One or more resource IDs (space-delimited). It should be a complete resource ID containing all information of 'Resource Id' arguments. If provided, no other 'Resource Id' arguments should be specified.

--name -n

The name of the Virtual Machine. You can configure the default using az configure --defaults vm=<name>.

--no-wait

Do not wait for the long-running operation to finish.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

az vm delete

Delete a VM.

az vm delete [--ids]
[--name]
[--no-wait]
[--resource-group]
[--subscription]
[--yes]

Examples

Delete a VM without a prompt for confirmation.

az vm delete -g MyResourceGroup -n MyVm --yes

Delete all VMs in a resource group.

az vm delete --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv)

Optional Parameters

--ids

One or more resource IDs (space-delimited). It should be a complete resource ID containing all information of 'Resource Id' arguments. If provided, no other 'Resource Id' arguments should be specified.

--name -n

The name of the Virtual Machine. You can configure the default using az configure --defaults vm=<name>.

--no-wait

Do not wait for the long-running operation to finish.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

--yes -y

Do not prompt for confirmation.

az vm generalize

Mark a VM as generalized, allowing it to be imaged for multiple deployments.

az vm generalize [--ids]
[--name]
[--no-wait]
[--resource-group]
[--subscription]

Examples

Deallocate, generalize, and capture a stopped virtual machine.

az vm deallocate -g MyResourceGroup -n MyVm
az vm generalize -g MyResourceGroup -n MyVm
az vm capture -g MyResourceGroup -n MyVm --vhd-name-prefix MyPrefix

Deallocate, generalize, and capture multiple stopped virtual machines.

vms_ids=$(az vm list -g MyResourceGroup --query "[].id" -o tsv)
az vm deallocate --ids {vms_ids}
az vm generalize --ids {vms_ids}
az vm capture --ids {vms_ids} --vhd-name-prefix MyPrefix

Optional Parameters

--ids

One or more resource IDs (space-delimited). It should be a complete resource ID containing all information of 'Resource Id' arguments. If provided, no other 'Resource Id' arguments should be specified.

--name -n

The name of the Virtual Machine. You can configure the default using az configure --defaults vm=<name>.

--no-wait

Do not wait for the long-running operation to finish.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

az vm get-instance-view

Get instance information about a VM.

az vm get-instance-view [--ids]
[--name]
[--resource-group]
[--subscription]

Examples

Use a resource group and name to get instance view information of a VM.

az vm get-instance-view -g MyResourceGroup -n MyVm

Get instance views for all VMs in a resource group.

az vm get-instance-view --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv)

Optional Parameters

--ids

One or more resource IDs (space-delimited). It should be a complete resource ID containing all information of 'Resource Id' arguments. If provided, no other 'Resource Id' arguments should be specified.

--name -n

The name of the Virtual Machine. You can configure the default using az configure --defaults vm=<name>.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

az vm list

List details of Virtual Machines.

az vm list [--resource-group]
[--show-details]
[--subscription]

Examples

List all VMs.

az vm list

List all VMs by resource group.

az vm list -g MyResourceGroup

List all VMs by resource group with details.

az vm list -g MyResourceGroup -d

Optional Parameters

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--show-details -d

Show public ip address, FQDN, and power states. command will run slow.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

az vm list-ip-addresses

List IP addresses associated with a VM.

az vm list-ip-addresses [--ids]
[--name]
[--resource-group]
[--subscription]

Examples

Get the IP addresses for a VM.

az vm list-ip-addresses -g MyResourceGroup -n MyVm

Get IP addresses for all VMs in a resource group.

az vm list-ip-addresses --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv)

Optional Parameters

--ids

One or more resource IDs (space-delimited). It should be a complete resource ID containing all information of 'Resource Id' arguments. If provided, no other 'Resource Id' arguments should be specified.

--name -n

The name of the Virtual Machine. You can configure the default using az configure --defaults vm=<name>.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

az vm list-sizes

List available sizes for VMs.

az vm list-sizes --location
[--subscription]

Examples

List the available VM sizes in the West US region.

az vm list-sizes -l westus

Required Parameters

--location -l

Location. Values from: az account list-locations. You can configure the default location using az configure --defaults location=<location>.

Optional Parameters

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

az vm list-skus

Get details for compute-related resource SKUs.

az vm list-skus [--all {false, true}]
[--location]
[--resource-type]
[--size]
[--subscription]
[--zone {false, true}]

Examples

List all SKUs in the West US region.

az vm list-skus -l westus

List all available vm sizes in the East US2 region which support availability zone.

az vm list-skus -l eastus2 --zone

List all available vm sizes in the East US2 region which support availability zone with name like "standard_ds1...".

az vm list-skus -l eastus2 --zone --size standard_ds1

List availability set related sku information in The West US region.

az vm list-skus -l westus --resource-type availabilitySets

Optional Parameters

--all

Show all information including vm sizes not available under the current subscription.

accepted values: false, true
--location -l

Location. Values from: az account list-locations. You can configure the default location using az configure --defaults location=<location>.

--resource-type -r

Resource types e.g. "availabilitySets", "snapshots", "disks", etc.

--size -s

Size name, partial name is accepted.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

--zone -z

Show all vm size supporting availability zones.

accepted values: false, true

az vm list-usage

List available usage resources for VMs.

az vm list-usage --location
[--subscription]

Examples

Get the compute resource usage for the West US region.

az vm list-usage -l westus

Required Parameters

--location -l

Location. Values from: az account list-locations. You can configure the default location using az configure --defaults location=<location>.

Optional Parameters

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

az vm list-vm-resize-options

List available resizing options for VMs.

az vm list-vm-resize-options [--ids]
[--name]
[--resource-group]
[--subscription]

Examples

List all available VM sizes for resizing.

az vm list-vm-resize-options -g MyResourceGroup -n MyVm

List available sizes for all VMs in a resource group.

az vm list-vm-resize-options --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv)

Optional Parameters

--ids

One or more resource IDs (space-delimited). It should be a complete resource ID containing all information of 'Resource Id' arguments. If provided, no other 'Resource Id' arguments should be specified.

--name -n

The name of the Virtual Machine. You can configure the default using az configure --defaults vm=<name>.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

az vm open-port

Opens a VM to inbound traffic on specified ports.

az vm open-port --port
[--apply-to-subnet]
[--ids]
[--name]
[--nsg-name]
[--priority]
[--resource-group]
[--subscription]

Examples

Open all ports on a VM to inbound traffic.

az vm open-port -g MyResourceGroup -n MyVm --port '*'

Open a range of ports on a VM to inbound traffic with the highest priority.

az vm open-port -g MyResourceGroup -n MyVm --port 80-100 --priority 100

Open all ports for all VMs in a resource group.

az vm open-port --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) --port '*'

Required Parameters

--port

The port or port range (ex: 80-100) to open inbound traffic to. Use '*' to allow traffic to all ports.

Optional Parameters

--apply-to-subnet

Allow inbound traffic on the subnet instead of the NIC.

--ids

One or more resource IDs (space-delimited). It should be a complete resource ID containing all information of 'Resource Id' arguments. If provided, no other 'Resource Id' arguments should be specified.

--name -n

The name of the virtual machine to open inbound traffic on.

--nsg-name

The name of the network security group to create if one does not exist. Ignored if an NSG already exists.

--priority

Rule priority, between 100 (highest priority) and 4096 (lowest priority). Must be unique for each rule in the collection.

default value: 900
--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

az vm perform-maintenance

The operation to perform maintenance on a virtual machine.

az vm perform-maintenance [--ids]
[--name]
[--resource-group]
[--subscription]

Optional Parameters

--ids

One or more resource IDs (space-delimited). It should be a complete resource ID containing all information of 'Resource Id' arguments. If provided, no other 'Resource Id' arguments should be specified.

--name -n

The name of the Virtual Machine. You can configure the default using az configure --defaults vm=<name>.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

az vm redeploy

Redeploy an existing VM.

az vm redeploy [--ids]
[--name]
[--no-wait]
[--resource-group]
[--subscription]

Examples

Redeploy a VM.

az vm redeploy -g MyResourceGroup -n MyVm

Redeploy all VMs in a resource group.

az vm redeploy --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv)

Optional Parameters

--ids

One or more resource IDs (space-delimited). It should be a complete resource ID containing all information of 'Resource Id' arguments. If provided, no other 'Resource Id' arguments should be specified.

--name -n

The name of the Virtual Machine. You can configure the default using az configure --defaults vm=<name>.

--no-wait

Do not wait for the long-running operation to finish.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

az vm resize

Update a VM's size.

az vm resize --size
[--ids]
[--name]
[--no-wait]
[--resource-group]
[--subscription]

Examples

Resize a VM.

az vm resize -g MyResourceGroup -n MyVm --size Standard_DS3_v2

Resize all VMs in a resource group.

az vm resize --size Standard_DS3_v2 --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv)

Required Parameters

--size

The VM size.

value from: az vm list-vm-resize-options

Optional Parameters

--ids

One or more resource IDs (space-delimited). It should be a complete resource ID containing all information of 'Resource Id' arguments. If provided, no other 'Resource Id' arguments should be specified.

--name -n

The name of the Virtual Machine. You can configure the default using az configure --defaults vm=<name>.

--no-wait

Do not wait for the long-running operation to finish.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

az vm restart

Restart VMs.

az vm restart [--force]
[--ids]
[--name]
[--no-wait]
[--resource-group]
[--subscription]

Examples

Restart a VM.

az vm restart -g MyResourceGroup -n MyVm

Restart all VMs in a resource group.

az vm restart --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv)

Optional Parameters

--force

Force the VM to restart by redeploying it. Use if the VM is unresponsive.

--ids

One or more resource IDs (space-delimited). It should be a complete resource ID containing all information of 'Resource Id' arguments. If provided, no other 'Resource Id' arguments should be specified.

--name -n

The name of the Virtual Machine. You can configure the default using az configure --defaults vm=<name>.

--no-wait

Do not wait for the long-running operation to finish.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

az vm show

Get the details of a VM.

az vm show [--ids]
[--name]
[--resource-group]
[--show-details]
[--subscription]

Examples

Show information about a VM.

az vm show -g MyResourceGroup -n MyVm -d

Get the details for all VMs in a resource group.

az vm show -d --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv)

Optional Parameters

--ids

One or more resource IDs (space-delimited). It should be a complete resource ID containing all information of 'Resource Id' arguments. If provided, no other 'Resource Id' arguments should be specified.

--name -n

The name of the Virtual Machine. You can configure the default using az configure --defaults vm=<name>.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--show-details -d

Show public ip address, FQDN, and power states. command will run slow.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

az vm start

Start a stopped VM.

az vm start [--ids]
[--name]
[--no-wait]
[--resource-group]
[--subscription]

Examples

Start a stopped VM.

az vm start -g MyResourceGroup -n MyVm

Start all VMs in a resource group.

az vm start --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv)

Start a stopped VM. (autogenerated)

az vm start --name MyVm --no-wait --resource-group MyResourceGroup

Optional Parameters

--ids

One or more resource IDs (space-delimited). It should be a complete resource ID containing all information of 'Resource Id' arguments. If provided, no other 'Resource Id' arguments should be specified.

--name -n

The name of the Virtual Machine. You can configure the default using az configure --defaults vm=<name>.

--no-wait

Do not wait for the long-running operation to finish.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

az vm stop

Power off (stop) a running VM.

az vm stop [--ids]
[--name]
[--no-wait]
[--resource-group]
[--skip-shutdown]
[--subscription]

Examples

Power off (stop) a running VM.

az vm stop --resource-group MyResourceGroup --name MyVm

Power off a running VM without shutting down.

az vm stop --resource-group MyResourceGroup --name MyVm --skip-shutdown

Power off VMs in a resource group.

az vm stop --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv)

Optional Parameters

--ids

One or more resource IDs (space-delimited). It should be a complete resource ID containing all information of 'Resource Id' arguments. If provided, no other 'Resource Id' arguments should be specified.

--name -n

The name of the Virtual Machine. You can configure the default using az configure --defaults vm=<name>.

--no-wait

Do not wait for the long-running operation to finish.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--skip-shutdown

Skip shutdown and power-off immediately.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

az vm update

Update the properties of a VM.

az vm update [--add]
[--disk-caching]
[--force-string]
[--ids]
[--license-type {None, Windows_Client, Windows_Server}]
[--name]
[--no-wait]
[--os-disk]
[--remove]
[--resource-group]
[--set]
[--subscription]
[--ultra-ssd-enabled {false, true}]
[--write-accelerator]

Examples

Add or update a tag.

az vm update -n name -g group --set tags.tagName=tagValue

Remove a tag.

az vm update -n name -g group --remove tags.tagName

Set the primary NIC of a VM.

az vm update -n name -g group --set networkProfile.networkInterfaces[1].primary=false networkProfile.networkInterfaces[0].primary=true

Add a new non-primary NIC to a VM.

az vm update -n name -g group --add networkProfile.networkInterfaces primary=false id={NIC_ID}

Remove the fourth NIC from a VM.

az vm update -n name -g group --remove networkProfile.networkInterfaces 3

Optional Parameters

--add

Add an object to a list of objects by specifying a path and key value pairs. Example: --add property.listProperty <key=value, string or JSON string>.

--disk-caching

Use singular value to apply across, or specify individual disks, e.g. 'os=ReadWrite 0=None 1=ReadOnly' should enable update os disk and 2 data disks.

--force-string

When using 'set' or 'add', preserve string literals instead of attempting to convert to JSON.

--ids

One or more resource IDs (space-delimited). It should be a complete resource ID containing all information of 'Resource Id' arguments. If provided, no other 'Resource Id' arguments should be specified.

--license-type

Specifies that the Windows image or disk was licensed on-premises. To enable Azure Hybrid Benefit for Windows Server, use 'Windows_Server'. To enable Multitenant Hosting Rights for Windows 10, use 'Windows_Client'. For more information see the Azure Windows VM online docs.

accepted values: None, Windows_Client, Windows_Server
--name -n

The name of the Virtual Machine. You can configure the default using az configure --defaults vm=<name>.

--no-wait

Do not wait for the long-running operation to finish.

--os-disk

Managed OS disk ID or name to swap to.

--remove

Remove a property or an element from a list. Example: --remove property.list OR --remove propertyToRemove.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--set

Update an object by specifying a property path and value to set. Example: --set property1.property2=.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

--ultra-ssd-enabled

Enables or disables the capability to have 1 or more managed data disks with UltraSSD_LRS storage account.

accepted values: false, true
--write-accelerator

Enable/disable disk write accelerator. Use singular value 'true/false' to apply across, or specify individual disks, e.g.'os=true 1=true 2=true' for os disk and data disks with lun of 1 & 2.

az vm wait

Place the CLI in a waiting state until a condition of the VM is met.

az vm wait [--created]
[--custom]
[--deleted]
[--exists]
[--ids]
[--interval]
[--name]
[--resource-group]
[--subscription]
[--timeout]
[--updated]

Examples

Wait until a VM is created.

az vm wait -g MyResourceGroup -n MyVm --created

Wait until all VMs in a resource group are deleted.

az vm wait --deleted --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv)

Optional Parameters

--created

Wait until created with 'provisioningState' at 'Succeeded'.

--custom

Wait until the condition satisfies a custom JMESPath query. E.g. provisioningState!='InProgress', instanceView.statuses[?code=='PowerState/running'].

--deleted

Wait until deleted.

--exists

Wait until the resource exists.

--ids

One or more resource IDs (space-delimited). It should be a complete resource ID containing all information of 'Resource Id' arguments. If provided, no other 'Resource Id' arguments should be specified.

--interval

Polling interval in seconds.

default value: 30
--name -n

The name of the Virtual Machine. You can configure the default using az configure --defaults vm=<name>.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

--timeout

Maximum wait in seconds.

default value: 3600
--updated

Wait until updated with provisioningState at 'Succeeded'.