Virtual Machines (VM) - az vm

Provision Linux or Windows virtual machines in seconds.

Commands

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 data disks attached to a VM.
az vm disk attach Attach a managed disk.
az vm disk detach
az vm encryption
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 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
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 capture

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

az vm capture --vhd-name-prefix VHD_NAME_PREFIX
[--ids IDS]
[--name NAME]
[--overwrite OVERWRITE]
[--resource-group RESOURCE_GROUP]
[--storage-container 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

---vhd-name-prefix
The VHD name prefix specify for the VM disks.

Optional Parameters

---ids
One or more resource IDs (space delimited). 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='.
---overwrite
Overwrite the existing disk file.
default value: True
---resource-group -g
Name of resource group. You can configure the default group using 'az configure --defaults group='.
---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 [--ids IDS]
[--name NAME]
[--resource-group 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)

Optional Parameters

---ids
One or more resource IDs (space delimited). 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='.
---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 NAME
--resource-group RESOURCE_GROUP
[--admin-password ADMIN_PASSWORD]
[--admin-username ADMIN_USERNAME]
[--attach-os-disk ATTACH_OS_DISK]
[--authentication-type {password, ssh}]
[--availability-set AVAILABILITY_SET]
[--custom-data CUSTOM_DATA]
[--data-disk-caching {None, ReadOnly, ReadWrite}]
[--data-disk-sizes-gb DATA_DISK_SIZES_GB]
[--generate-ssh-keys GENERATE_SSH_KEYS]
[--image IMAGE]
[--location LOCATION]
[--nics NICS]
[--no-wait NO_WAIT]
[--nsg NSG]
[--nsg-rule {RDP, SSH}]
[--os-disk-caching {ReadOnly, ReadWrite}]
[--os-disk-name OS_DISK_NAME]
[--os-type {linux, windows}]
[--private-ip-address PRIVATE_IP_ADDRESS]
[--public-ip-address PUBLIC_IP_ADDRESS]
[--public-ip-address-allocation {dynamic, static}]
[--public-ip-address-dns-name PUBLIC_IP_ADDRESS_DNS_NAME]
[--secrets SECRETS]
[--size SIZE]
[--ssh-dest-key-path SSH_DEST_KEY_PATH]
[--ssh-key-value SSH_KEY_VALUE]
[--storage-account STORAGE_ACCOUNT]
[--storage-container-name STORAGE_CONTAINER_NAME]
[--storage-sku {Premium_LRS, Standard_GRS, Standard_LRS, Standard_RAGRS, Standard_ZRS}]
[--subnet SUBNET]
[--subnet-address-prefix SUBNET_ADDRESS_PREFIX]
[--tags TAGS]
[--use-unmanaged-disk USE_UNMANAGED_DISK]
[--validate VALIDATE]
[--vnet-address-prefix VNET_ADDRESS_PREFIX]
[--vnet-name 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"

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
---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
---location -l
Location in which to create VM and related resources. Defaults 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.
---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 [--ids IDS]
[--name NAME]
[--no-wait NO_WAIT]
[--resource-group RESOURCE_GROUP]

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

Optional Parameters

---ids
One or more resource IDs (space delimited). 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='.
---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='.

az vm delete

The operation to delete a virtual machine.

az vm delete [--ids IDS]
[--name NAME]
[--no-wait NO_WAIT]
[--resource-group RESOURCE_GROUP]
[--yes YES]

Examples

Delete a VM without a prompt for confirmation.

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

Delete a virtual machine by Ids

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

Optional Parameters

---ids
One or more resource IDs (space delimited). 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='.
---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='.
---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 SECRETS
[--certificate-store 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 [--ids IDS]
[--name NAME]
[--no-wait NO_WAIT]
[--resource-group RESOURCE_GROUP]

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

Optional Parameters

---ids
One or more resource IDs (space delimited). 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='.
---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='.

az vm get-instance-view

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

az vm get-instance-view [--ids IDS]
[--name NAME]
[--resource-group 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)

Optional Parameters

---ids
One or more resource IDs (space delimited). 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='.
---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 RESOURCE_GROUP]
[--show-details 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 [--ids IDS]
[--name NAME]
[--resource-group 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

---ids
One or more resource IDs (space delimited). 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='.
---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 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 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 [--ids IDS]
[--name NAME]
[--resource-group 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)

Optional Parameters

---ids
One or more resource IDs (space delimited). 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='.
---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 --port PORT
[--apply-to-subnet APPLY_TO_SUBNET]
[--ids IDS]
[--name NAME]
[--nsg-name NSG_NAME]
[--priority PRIORITY]
[--resource-group RESOURCE_GROUP]

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

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

az vm redeploy

The operation to redeploy a virtual machine.

az vm redeploy [--ids IDS]
[--name NAME]
[--no-wait NO_WAIT]
[--resource-group RESOURCE_GROUP]

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)

Optional Parameters

---ids
One or more resource IDs (space delimited). 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='.
---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='.

az vm resize

Update vm size.

az vm resize --size SIZE
[--ids IDS]
[--name NAME]
[--no-wait NO_WAIT]
[--resource-group RESOURCE_GROUP]

Examples

Resize a VM.

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

Resize VMs by VM Ids

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

Required Parameters

---size
Sizes such as Standard_A4, Standard_F4s, etc.

Optional Parameters

---ids
One or more resource IDs (space delimited). 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='.
---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='.

az vm restart

The operation to restart a virtual machine.

az vm restart [--ids IDS]
[--name NAME]
[--no-wait NO_WAIT]
[--resource-group RESOURCE_GROUP]

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)

Optional Parameters

---ids
One or more resource IDs (space delimited). 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='.
---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='.

az vm show

az vm show [--ids IDS]
[--name NAME]
[--resource-group RESOURCE_GROUP]
[--show-details 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)

Optional Parameters

---ids
One or more resource IDs (space delimited). 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='.
---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 start

The operation to start a virtual machine.

az vm start [--ids IDS]
[--name NAME]
[--no-wait NO_WAIT]
[--resource-group RESOURCE_GROUP]

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)

Optional Parameters

---ids
One or more resource IDs (space delimited). 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='.
---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='.

az vm stop

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

az vm stop [--ids IDS]
[--name NAME]
[--no-wait NO_WAIT]
[--resource-group RESOURCE_GROUP]

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)

Optional Parameters

---ids
One or more resource IDs (space delimited). 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='.
---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='.

az vm update

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

az vm update [--add ADD]
[--ids IDS]
[--name NAME]
[--no-wait NO_WAIT]
[--remove REMOVE]
[--resource-group RESOURCE_GROUP]
[--set 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

Optional Parameters

---add
Add an object to a list of objects by specifying a path and key value pairs. Example: --add property.listProperty .
---ids
One or more resource IDs (space delimited). 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='.
---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.
---resource-group -g
Name of resource group. You can configure the default group using 'az configure --defaults group='.
---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 [--created CREATED]
[--custom CUSTOM]
[--deleted DELETED]
[--exists EXISTS]
[--ids IDS]
[--interval INTERVAL]
[--name NAME]
[--resource-group RESOURCE_GROUP]
[--timeout TIMEOUT]
[--updated 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)

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.
---ids
One or more resource IDs (space delimited). 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='.
---resource-group -g
Name of resource group. You can configure the default group using 'az configure --defaults group='.
---timeout
Maximum wait in seconds.
default value: 3600
---updated
Wait till updated with provisioningState at 'Succeeded'.