Virtual Machines (VM) - az vm

Provision Linux or Windows virtual machines in seconds.

Commands

az vm assign-identity Enable managed service identity on a VM.
az vm availability-set Group resources into availability sets for high-availability requirements.
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 Lists all availability sets in a resource group.
az vm availability-set list-sizes Lists all available virtual machine sizes that can be used to create a new virtual machine in an existing availability set.
az vm availability-set show Retrieves information about an availability set.
az vm availability-set update Update an Azure Availability Set.
az vm boot-diagnostics Troubleshoot the start up 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 Captures the VM by copying virtual hard disks of the VM and outputs a template that can be used to create similar VMs.
az vm convert Convert a VM with unmanaged disks to use managed disks.
az vm create Create an Azure Virtual Machine.
az vm deallocate Shuts down the virtual machine and releases the compute resources.
az vm delete The operation to delete a virtual machine.
az vm diagnostics Configure the Azure Virtual Machine diagnostics extension.
az vm diagnostics get-default-config Show the default config file which defines data to be collected.
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 disk.
az vm disk detach
az vm encryption Manage encryption of VM disks.
az vm encryption disable Disable disk encryption on OS disk, Data disks, or both.
az vm encryption enable Enable disk encryption on OS disk, Data disks, or both.
az vm encryption show Show the encryption status.
az vm extension Extend the functionality of your VMs with extensions.
az vm extension delete The operation to delete the extension.
az vm extension image Find the available VM extensions for your subscription and region.
az vm extension image list Vm extension image list.
az vm extension image list-names Gets a list of virtual machine extension image types.
az vm extension image list-versions Gets a list of virtual machine extension image versions.
az vm extension image show Gets a virtual machine extension image.
az vm extension list List the extensions attached to a VM in a resource group.
az vm extension set Create/update extensions for a VM in a resource group.
az vm extension show The operation to get the extension.
az vm format-secret Format secrets to be used in az vm create --secrets.
az vm generalize Sets the state of the virtual machine to generalized.
az vm get-instance-view Get information about a VM including instance information (powerState).
az vm image Virtual machine images that are available in the Azure Marketplace.
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 Show a VM image available in the Azure Marketplace.
az vm list List information about Virtual Machines.
az vm list-ip-addresses Get IP addresses from one or more Virtual Machines.
az vm list-sizes Lists all available virtual machine sizes for a subscription in a location.
az vm list-usage Gets, for the specified location, the current compute resource usage information as well as the limits for compute resources under the subscription.
az vm list-vm-resize-options Lists all available virtual machine sizes to which the specified virtual machine can be resized.
az vm nic Manage network interfaces, see also 'az network nic'.
az vm nic add Add network interface configurations to the virtual machine.
az vm nic list List network interface configurations attached to a virtual machine.
az vm nic remove Remove network interface configurations from the virtual machine.
az vm nic set Replace existing network interface configurations on the virtual machine.
az vm nic show Show details of a network interface configuration attached to a virtual machine.
az vm open-port Opens a VM to inbound traffic on specified ports by adding a security rule to the network security group (NSG) that is attached to the VM's network interface (NIC) or subnet.
az vm redeploy The operation to redeploy a virtual machine.
az vm resize Update VM size.
az vm restart The operation to restart a virtual machine.
az vm show Show details of a VM.
az vm start The operation to start a virtual machine.
az vm stop The operation to power off (stop) a virtual machine.
az vm unmanaged-disk Manage the unmanaged data disks attached to a VM.
az vm unmanaged-disk attach Attach an unmanaged disk.
az vm unmanaged-disk detach
az vm unmanaged-disk list List disks for a Virtual Machine.
az vm update Update the properties of a VM.
az vm user Manage a user account on a VM.
az vm user delete Remove a user(not supported on Windows VM).
az vm user reset-ssh Reset the SSH configuration on a VM.
az vm user update Update or Add(only on Linux VM) users.
az vm wait Place the CLI in a waiting state until a condition of the VM is met.

az vm assign-identity

Required to authenticate and interact with other Azure services using bearer tokens.

az vm assign-identity --name
--resource-group
[--port]
[--role]
[--scope]

Examples

Enable identity on a VM. It will have a role of 'Reader' to the VM's resource group

az vm assign-identity -g MyResourceGroup -n MyVm --role Reader

Required Parameters

--name -n

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

--resource-group -g

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

Optional Parameters

--port

The port to fetch AAD token. Default: 50342.

--role

Role name or id the managed identity will be assigned.

default value: Contributor
--scope

The scope the managed identity has access to. Default: VM/VMSS's resource group.

az vm capture

For an end-to-end tutorial, see https://docs.microsoft.com/azure/virtual-machines/virtual-machines-linux-capture-image.

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

Examples

Process to 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

The process to 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

--name -n

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

--resource-group -g

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

--vhd-name-prefix

The VHD name prefix specify for the VM disks.

Optional Parameters

--overwrite

Overwrite the existing disk file.

default value: True
--storage-container

The storage account container name to save the disks.

default value: vhds

az vm convert

Convert a VM with unmanaged disks to use managed disks.

az vm convert --name
--resource-group

Examples

Convert a VM with unmanaged disks to use managed disks.

az vm convert -g MyResourceGroup -n MyVm

Convert VM with unmanaged disks to managed by Ids

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

Required Parameters

--name -n

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

--resource-group -g

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

az vm create

For an end-to-end tutorial, see https://docs.microsoft.com/azure/virtual-machines/virtual-machines-linux-quick-create-cli.

az vm create --name
--resource-group
[--admin-password]
[--admin-username]
[--assign-identity]
[--attach-data-disks]
[--attach-os-disk]
[--authentication-type {password, ssh}]
[--availability-set]
[--custom-data]
[--data-disk-caching {None, ReadOnly, ReadWrite}]
[--data-disk-sizes-gb]
[--generate-ssh-keys]
[--image]
[--license-type {Windows_Client, Windows_Server}]
[--location]
[--nics]
[--no-wait]
[--nsg]
[--nsg-rule {RDP, SSH}]
[--os-disk-caching {ReadOnly, ReadWrite}]
[--os-disk-name]
[--os-type {linux, windows}]
[--private-ip-address]
[--public-ip-address]
[--public-ip-address-allocation {dynamic, static}]
[--public-ip-address-dns-name]
[--role]
[--scope]
[--secrets]
[--size]
[--ssh-dest-key-path]
[--ssh-key-value]
[--storage-account]
[--storage-container-name]
[--storage-sku {Premium_LRS, Standard_GRS, Standard_LRS, Standard_RAGRS, Standard_ZRS}]
[--subnet]
[--subnet-address-prefix]
[--tags]
[--use-unmanaged-disk]
[--validate]
[--vnet-address-prefix]
[--vnet-name]

Examples

Create a simple Ubuntu VM with automatic SSH authentication.

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

Create a simple 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 (see `az image create` for generation information).

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

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

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

Create an Ubuntu Linux VM and provide a cloud-init script (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 Linux VM with SSH key authentication, add a public DNS entry, and then add it to an existing virtual network and availability set.

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

Create a simple Ubuntu Linux VM with a public IP address, DNS entry, 2 data disk(10GB, 20GB), and then generate ssh key pairs under ~/.ssh.

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 an Debian VM and with Key Vault secrets. The secrets are placed in /var/lib/waagent and each certificate file is named with the hex thumbprint.

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 format-secret -s "$secrets") 
                        
                        az vm create -g group-name -n vm-name --admin-username deploy    --image debian --secrets "$vm_secrets"

Create a VM with Managed Service Identity. The VM will have a 'Contributor' Role with access to the current resource group

az vm create -n MyVm -g MyResourceGroup --assign-identity --image centos

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

Optional Parameters

--admin-password

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

--admin-username

Username for the VM.

default value: appveyor
--assign-identity

Enables the VM/VMSS to autonomously, using its own managed identity, to directly authenticate and interact with other Azure services using bearer tokens.

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

accepted values: password, ssh
--availability-set

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

--custom-data

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

--data-disk-caching

Storage caching type for the VM data disk(s).

accepted values: None, ReadOnly, ReadWrite
--data-disk-sizes-gb

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

--generate-ssh-keys

Generate SSH public and private key files if missing.

--image

The name of the operating system image (URN alias, URN, Custom Image name or ID, or VHD Blob URI). In many cases, this parameter is required, but can be replaced by others (for example, --attach-os-disk).

URN aliases: CentOS, CoreOS, Debian, openSUSE, RHEL, SLES, UbuntuLTS, Win2008R2SP1, Win2012Datacenter, Win2012R2Datacenter. Example URN: MicrosoftWindowsServer:WindowsServer:2012-R2-Datacenter:latest Example Custom Image Resource ID or Name: /subscriptions/subscription-id/resourceGroups/MyResourceGroup/providers/Microsoft.Compute/images/MyImage Example URI: http://.blob.core.windows.net/vhds/osdiskimage.vhd.

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

License type if the Windows image or disk used was licensed on-premises.

accepted values: 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.

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

Storage caching type for the VM OS disk.

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

The name of the new VM OS disk.

--os-type

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

accepted values: linux, windows
--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
default value: dynamic
--public-ip-address-dns-name

Globally unique DNS name for a newly created Public IP.

--role

Role name or id the managed identity will be assigned.

default value: Contributor
--scope

The scope the managed identity has access to. Default: VM/VMSS's resource group.

--secrets

One or many Key Vault secrets as JSON strings or files via @ 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/en-us/pricing/details/virtual-machines/ for size info.

default value: Standard_DS1_v2
--ssh-dest-key-path

Destination file path on the VM for the SSH key.

--ssh-key-value

The SSH public key or public key file path.

--storage-account

Only applicable when use 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 use with '--use-unmanaged-disk'. Name of the storage container for the VM OS disk. Default: vhds.

--storage-sku

The sku of storage account to persist VM. By default, only Standard_LRS and Premium_LRS are allowed. Using with --use-unmanaged-disk, all are available.

accepted values: Premium_LRS, Standard_GRS, Standard_LRS, Standard_RAGRS, Standard_ZRS
--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
--tags

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

--use-unmanaged-disk

Do not use managed disk to persist VM.

--validate

Generate and validate the ARM template without creating any resources.

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

az vm deallocate

For an end-to-end tutorial, see https://docs.microsoft.com/azure/virtual-machines/virtual-machines-linux-capture-image.

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

Examples

Process to 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

The process to 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

--name -n

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

--resource-group -g

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

Optional Parameters

--no-wait

Do not wait for the long running operation to finish.

az vm delete

The operation to delete a virtual machine.

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

Examples

Delete a VM without a prompt for confirmation.

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

Delete a virtual machine by Ids

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

Required Parameters

--name -n

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

--resource-group -g

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

Optional Parameters

--no-wait

Do not wait for the long running operation to finish.

--yes -y

Do not prompt for confirmation.

az vm format-secret

Transform secrets into a form consumed by VMs and VMSS create via --secrets.

az vm format-secret --secrets
[--certificate-store]

Examples

Create a self-signed certificate with a the default policy and add to a virtual machine

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 format-secret -s "$secrets") 
                        
                        az vm create -g group-name -n vm-name --admin-username deploy    --image debian --secrets "$vm_secrets"

Required Parameters

--secrets -s

Space separated list of Key Vault secret URIs. Perhaps, produced by 'az keyvault secret list-versions --vault-name vaultname -n cert1 --query "[?attributes.enabled].id" -o tsv'.

Optional Parameters

--certificate-store

Certificate store the secret will be applied (Windows only).

az vm generalize

For an end-to-end tutorial, see https://docs.microsoft.com/azure/virtual-machines/virtual-machines-linux-capture-image.

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

Examples

Process to 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

The process to 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

--name -n

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

--resource-group -g

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

Optional Parameters

--no-wait

Do not wait for the long running operation to finish.

az vm get-instance-view

Get information about a VM including instance information (powerState).

az vm get-instance-view --name
--resource-group

Examples

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

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

Get instance view by Ids

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

Required Parameters

--name -n

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

--resource-group -g

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

az vm list

For more information on querying information about Virtual Machines, see https://docs.microsoft.com/en-us/cli/azure/query-az-cli2.

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

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

--show-details -d

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

az vm list-ip-addresses

Get IP addresses from one or more Virtual Machines.

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

Examples

Get the IP addresses for a VM.

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

Get IP addresses for VMs by Ids

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

Optional Parameters

--name -n

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

--resource-group -g

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

az vm list-sizes

Lists all available virtual machine sizes for a subscription in a location.

az vm list-sizes --location

Examples

List the available VM sizes in West US.

az vm list-sizes -l westus

Required Parameters

--location -l

Location. You can configure the default location using az configure --defaults location=.

az vm list-usage

Gets, for the specified location, the current compute resource usage information as well as the limits for compute resources under the subscription.

az vm list-usage --location

Examples

Get the compute resource usage for West US.

az vm list-usage -l westus

Required Parameters

--location -l

Location. You can configure the default location using az configure --defaults location=.

az vm list-vm-resize-options

Lists all available virtual machine sizes to which the specified virtual machine can be resized.

az vm list-vm-resize-options --name
--resource-group

Examples

List all available VM sizes for resizing.

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

List all available VM sizes for resizing by VM Ids

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

Required Parameters

--name -n

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

--resource-group -g

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

az vm open-port

Opens a VM to inbound traffic on specified ports by adding a security rule to the network security group (NSG) that is attached to the VM's network interface (NIC) or subnet.

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

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 multiple VMs by Ids

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

Required Parameters

--name -n

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

--port

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

--resource-group -g

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

Optional Parameters

--apply-to-subnet

Allow inbound traffic on the subnet instead of the NIC.

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

az vm redeploy

The operation to redeploy a virtual machine.

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

Examples

Redeploy a VM.

az vm redeploy -g MyResourceGroup -n MyVm

Redeploy VMs by VM Ids

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

Required Parameters

--name -n

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

--resource-group -g

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

Optional Parameters

--no-wait

Do not wait for the long running operation to finish.

az vm resize

Update VM size.

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

Examples

Resize a VM.

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

Resize VMs by VM Ids

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

Required Parameters

--name -n

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

--resource-group -g

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

--size

Sizes such as Standard_A4, Standard_F4s, etc.

Optional Parameters

--no-wait

Do not wait for the long running operation to finish.

az vm restart

The operation to restart a virtual machine.

az vm restart --name
--resource-group
[--no-wait]

Examples

Restart a VM.

az vm restart -g MyResourceGroup -n MyVm

Restart VM by by VM Ids

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

Required Parameters

--name -n

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

--resource-group -g

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

Optional Parameters

--no-wait

Do not wait for the long running operation to finish.

az vm show

Show details of a VM.

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

Examples

Show information about a VM.

az vm show -g MyResourceGroup -n MyVm -d

Show VM details by by VM Ids

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

Required Parameters

--name -n

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

--resource-group -g

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

Optional Parameters

--show-details -d

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

az vm start

The operation to start a virtual machine.

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

Examples

Start a stopped VM.

az vm start -g MyResourceGroup -n MyVm

Start stopped VMs by by VM Ids

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

Required Parameters

--name -n

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

--resource-group -g

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

Optional Parameters

--no-wait

Do not wait for the long running operation to finish.

az vm stop

The operation to power off (stop) a virtual machine.

az vm stop --name
--resource-group
[--no-wait]

Examples

Stop a running VM.

az vm stop -g MyResourceGroup -n MyVm

Stop running VMs by by VM Ids

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

Required Parameters

--name -n

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

--resource-group -g

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

Optional Parameters

--no-wait

Do not wait for the long running operation to finish.

az vm update

Update VM objects and properties using paths that correspond to 'az vm show'.

az vm update --name
--resource-group
[--add]
[--no-wait]
[--remove]
[--set]

Examples

Add or update a tag.

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

Remove a tag.

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

Set the primary NIC of a VM.

az  -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  -n name -g group --add networkProfile.networkInterfaces primary=false id=

Remove the fourth NIC from a VM.

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

Required Parameters

--name -n

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

--resource-group -g

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

Optional Parameters

--add

Add an object to a list of objects by specifying a path and key value pairs. Example: --add property.listProperty .

--no-wait

Do not wait for the long running operation to finish.

--remove

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

--set

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

az vm wait

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

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

Examples

Wait until the VM is created.

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

Wait until VMs are deleted by Ids

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

Required Parameters

--name -n

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

--resource-group -g

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

Optional Parameters

--created

Wait till 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 till deleted.

--exists

Wait till the resource exists.

--interval

Polling interval in seconds.

default value: 30
--timeout

Maximum wait in seconds.

default value: 3600
--updated

Wait till updated with provisioningState at 'Succeeded'.