az vm

Provision Linux or Windows virtual machines.

Commands

az vm assign-identity Enable managed service identity on a VM.
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 Detatch a managed disk from a VM.
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 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 format-secret Transform secrets into a form that can be used by VMs and VMSSes.
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 image Information on available virtual machine images.
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 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 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 Manage open ports on a VM.
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 (PREVIEW) Manage run commands on a Virtual Machine.
az vm run-command invoke 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 show Get the details of a VM.
az vm start Start a stopped VM.
az vm stop 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 Detatch an unmanaged disk from a VM.
az vm unmanaged-disk list List unamanaged 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 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

Enable managed service identity on a VM.

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

Examples

Enable identity on a VM with the 'Reader' role.

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=<name>`.
--resource-group -g
Name of resource group. You can configure the default group using `az configure --defaults group=<name>`.

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.

az vm capture

Capture information for a stopped VM.

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

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

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

Required Parameters

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

az vm create

Create an Azure Virtual Machine.

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

Create a CentOS VM with Managed Service Identity. The VM will have a 'Contributor' role with access to a storage account.

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

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

--admin-password
Password for the VM if authentication type is 'Password'.
--admin-username
Username for the VM.
default value: appveyor
--asgs
Space separated list of existing application security groups to associate with the VM.
--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. The keys will be stored in the ~/.ssh directory.
--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.`.
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.
--secrets
One or many Key Vault secrets as JSON strings or files via `@<file 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/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.
--zone -z
Availability zone into which to provision the resource.
accepted values: 1, 2, 3

az vm deallocate

Deallocate a VM.

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

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

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

Optional Parameters

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

az vm delete

Delete a VM.

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 all VMs in a resource group.

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=<name>`.
--resource-group -g
Name of resource group. You can configure the default group using `az configure --defaults group=<name>`.

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 that can be used by VMs and VMSSes.

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

Examples

Create a self-signed certificate with the default policy, and add it 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

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

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

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

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

Optional Parameters

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

az vm get-instance-view

Get instance information about a VM.

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

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)

Required Parameters

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

az vm list

List details of Virtual Machines.

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=<name>`.
--show-details -d
Show public ip address, FQDN, and power states. command will run slow.

az vm list-ip-addresses

List IP addresses associated with a VM.

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 all VMs in a resource group.

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=<name>`.
--resource-group -g
Name of resource group. You can configure the default group using `az configure --defaults group=<name>`.

az vm list-sizes

List available sizes for VMs.

az vm list-sizes --location

Examples

List the available VM sizes in the West US region.

az vm list-sizes -l westus

Required Parameters

--location -l
Location. You can configure the default location using `az configure --defaults location=<location>`.

az vm list-skus

Get details for compute-related resource SKUs.

az vm list-skus [--location]

Examples

List all SKUs in the West US region.

az vm list-skus -l westus

Optional Parameters

--location -l
Location. You can configure the default location using `az configure --defaults location=<location>`.

az vm list-usage

List available usage resources for VMs.

az vm list-usage --location

Examples

Get the compute resource usage for the West US region.

az vm list-usage -l westus

Required Parameters

--location -l
Location. You can configure the default location using `az configure --defaults location=<location>`.

az vm list-vm-resize-options

List available resizing options for VMs.

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

Required Parameters

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

az vm open-port

Manage open ports on a VM.

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 all VMs in a resource group.

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

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

The operation to perform maintenance on a virtual machine.

az vm perform-maintenance --name
--resource-group

Required Parameters

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

az vm redeploy

Redeploy an existing VM.

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

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)

Required Parameters

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

Optional Parameters

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

az vm resize

Update a VM's 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 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

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

Restart VMs.

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

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)

Required Parameters

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

Optional Parameters

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

az vm show

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

Get the details for all VMs in a resource group.

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=<name>`.
--resource-group -g
Name of resource group. You can configure the default group using `az configure --defaults group=<name>`.

Optional Parameters

--show-details -d
Show public ip address, FQDN, and power states. command will run slow.

az vm start

Start a stopped VM.

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

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)

Required Parameters

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

Optional Parameters

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

az vm stop

Stop a running VM.

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

Examples

Stop a running VM.

az vm stop -g MyResourceGroup -n MyVm

Stop all VMs in a resource group.

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=<name>`.
--resource-group -g
Name of resource group. You can configure the default group using `az configure --defaults group=<name>`.

Optional Parameters

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

az vm update

Update the properties of a VM.

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

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=

Remove the fourth NIC from a VM.

az vm update -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=<name>`.
--resource-group -g
Name of resource group. You can configure the default group using `az configure --defaults group=<name>`.

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

Required Parameters

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

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