az vm
Manage Azure virtual machines.
Commands
| Name | Description | Type | Status |
|---|---|---|---|
| az vm create |
Create a virtual machine and its supporting network resources. |
Core | Preview |
| az vm deallocate |
Deallocate a virtual machine and release its compute resources. |
Core | Preview |
| az vm delete |
Delete a virtual machine. |
Core | Preview |
| az vm get-instance-view |
Get instance information about a virtual machine. |
Core | Preview |
| az vm list |
List virtual machines. |
Core | Preview |
| az vm show |
Show details for a virtual machine. |
Core | Preview |
| az vm start |
Start a stopped virtual machine. |
Core | Preview |
| az vm stop |
Power off (stop) a running virtual machine. |
Core | Preview |
az vm create
Create a virtual machine and its supporting network resources.
Provision an Azure virtual machine in the specified resource group along with the supporting virtual network, subnet, network security group, network interface, and public IP address in a single orchestrated call. The VM size, administrator credentials, and target location must all be provided. A resource name supplied for --virtual-network-name is created if it does not already exist in the resource group. The network interface is named {vm}VMNic; to attach existing network interfaces instead, use --nics. By default a network security group named {vm}NSG is created, or updated if it already exists. A network security group the command creates has one inbound rule for the image's operating system, allowing traffic from any source: rdp (TCP port 3389) for Windows or default-allow-ssh (TCP port 22) for Linux. Pass --nsg a name to reuse the network security group of that name, unchanged, when it exists and create it when it does not, a resource ID to attach an existing network security group, or "" to create none. By default a Standard, static public IP address named {vm}PublicIP is created, or updated if it already exists. Pass --public-ip-address a name to reuse the public IP address of that name when it exists and create it when it does not, a resource ID to attach an existing public IP address, or "" to create none. Use --zone to place the virtual machine in a single availability zone. Use --storage-sku to choose the storage SKU of the managed OS disk, as either SKU or os=SKU, such as Premium_LRS, StandardSSD_LRS, Standard_LRS, Premium_ZRS, or StandardSSD_ZRS; when omitted, the service default applies. Numeric data-disk IDs are not supported because this command does not create data disks. Use --os-disk-delete-option with Delete to delete the OS disk when the virtual machine is deleted, or Detach to keep it; when omitted, the service default (Detach) applies. Pass --tags to tag the virtual machine and every network resource the command creates; resources the command only attaches keep their own tags, such as network interfaces passed to --nics, the virtual network of an existing subnet selected with --subnet, or an existing network security group or public IP address. The command returns the new virtual machine with the power state and the public and private IP addresses that az vm show -d reports.
az vm create --admin-username
--location
--name
--resource-group
--size
[--accelerated-networking]
[--address-prefixes]
[--admin-password]
[--enable-secure-boot]
[--enable-vtpm]
[--image]
[--nic-delete-option]
[--nics]
[--nsg]
[--os-disk-delete-option]
[--os-disk-secure-vm-disk-encryption-set]
[--os-disk-security-encryption-type {VMGuestStateOnly, DiskWithVMGuestState, NonPersistedTPM}]
[--profile]
[--public-ip-address]
[--security-type {TrustedLaunch, ConfidentialVM, Standard}]
[--ssh-key-values]
[--storage-sku]
[--subnet]
[--subnet-address-prefixes]
[--subnet-names]
[--subscription-id]
[--tags]
[--virtual-network-name]
[--zone]
Examples
Create a VM from a marketplace image URN
az vm create --name myvm --resource-group myrg --location eastus --size Standard_D2s_v5 --image MicrosoftWindowsServer:WindowsServer:2022-datacenter-azure-edition:latest --admin-username azureuser --admin-password 'P@ssw0rd123!' --virtual-network-name myvm-vnet --subscription-id 00000000-0000-0000-0000-000000000000
Create using shell variables for credentials
az vm create --name $vmName --resource-group $rg --location eastus --size Standard_D2s_v5 --admin-username $adminUser --admin-password $adminPwd --virtual-network-name $vmName-vnet --subscription-id $subId
Create a VM that uses an existing network security group
az vm create --name myvm --resource-group myrg --location eastus --size Standard_D2s_v5 --admin-username azureuser --admin-password 'P@ssw0rd123!' --virtual-network-name myvm-vnet --nsg mynsg
Create with an SSH public key
az vm create --name myvm --resource-group myrg --location eastus --size Standard_D2s_v5 --image Canonical:0001-com-ubuntu-server-jammy:22_04-lts-gen2:latest --admin-username azureuser --admin-password 'P@ssw0rd123!' --ssh-key-values ~/.ssh/id_rsa.pub --virtual-network-name myvm-vnet --subscription-id 00000000-0000-0000-0000-000000000000
Create with a different image URN
az vm create --name myvm --resource-group myrg --location eastus --size Standard_D2s_v5 --image Canonical:0001-com-ubuntu-server-jammy:22_04-lts-gen2:latest --admin-username azureuser --admin-password 'P@ssw0rd123!' --virtual-network-name myvm-vnet --subscription-id 00000000-0000-0000-0000-000000000000
Create a VM with Standard security type
az vm create --name myvm --resource-group myrg --location eastus --size Standard_D2s_v5 --image MicrosoftWindowsServer:WindowsServer:2022-datacenter-azure-edition:latest --security-type Standard --admin-username azureuser --admin-password 'P@ssw0rd123!' --virtual-network-name myvm-vnet --nsg myvm-nsg --subscription-id 00000000-0000-0000-0000-000000000000
Create a Confidential VM
az vm create --name myvm --resource-group myrg --location eastus --size Standard_DC2as_v5 --image MicrosoftWindowsServer:WindowsServer:2022-datacenter-azure-edition:latest --security-type ConfidentialVM --os-disk-security-encryption-type VMGuestStateOnly --admin-username azureuser --admin-password 'P@ssw0rd123!' --virtual-network-name myvm-vnet --nsg myvm-nsg --subscription-id 00000000-0000-0000-0000-000000000000
Create a Trusted Launch VM with secure boot disabled
az vm create --name myvm --resource-group myrg --location eastus --size Standard_D2s_v5 --image MicrosoftWindowsServer:WindowsServer:2022-datacenter-azure-edition:latest --security-type TrustedLaunch --enable-secure-boot false --enable-vtpm true --admin-username azureuser --admin-password 'P@ssw0rd123!' --virtual-network-name myvm-vnet
Create a VM with a named public IP address
az vm create --name myvm --resource-group myrg --location eastus --size Standard_D2s_v5 --admin-username azureuser --admin-password 'P@ssw0rd123!' --virtual-network-name myvm-vnet --public-ip-address myvm-ip
Create a VM without a public IP address
az vm create --name myvm --resource-group myrg --location eastus --size Standard_D2s_v5 --admin-username azureuser --admin-password 'P@ssw0rd123!' --virtual-network-name myvm-vnet --public-ip-address ""
Create a VM with tags
az vm create --name myvm --resource-group myrg --location eastus --size Standard_D2s_v5 --admin-username azureuser --admin-password 'P@ssw0rd123!' --virtual-network-name myvm-vnet --tags env=prod owner=team-a
Create a VM in availability zone 1
az vm create --name myvm --resource-group myrg --location eastus --size Standard_D2s_v5 --zone 1 --admin-username azureuser --admin-password 'P@ssw0rd123!' --virtual-network-name myvm-vnet
Create a VM with a Premium SSD OS disk
az vm create --name myvm --resource-group myrg --location eastus --size Standard_D2s_v5 --storage-sku Premium_LRS --admin-username azureuser --admin-password 'P@ssw0rd123!' --virtual-network-name myvm-vnet
Create a VM whose OS disk is deleted with the VM
az vm create --name myvm --resource-group myrg --location eastus --size Standard_D2s_v5 --os-disk-delete-option Delete --admin-username azureuser --admin-password 'P@ssw0rd123!' --virtual-network-name myvm-vnet
Required Parameters
The administrator username.
| Property | Value |
|---|---|
| Parameter group: | Authentication Arguments |
Location for all resources.
The name of the virtual machine.
The resource group name.
| Property | Value |
|---|---|
| Value from: | az group list |
The size of the virtual machine.
Optional Parameters
The following parameters are optional, but depending on the context, one or more might become required for the command to execute successfully.
Whether the network interface enables accelerated networking. Off unless set.
| Property | Value |
|---|---|
| Parameter group: | Network Arguments |
Address prefixes for the virtual network.
| Property | Value |
|---|---|
| Parameter group: | Network Arguments |
The administrator password.
| Property | Value |
|---|---|
| Parameter group: | Authentication Arguments |
Enable or disable secure boot in the VM UEFI settings.
| Property | Value |
|---|---|
| Parameter group: | Security Arguments |
Enable or disable vTPM in the VM UEFI settings.
| Property | Value |
|---|---|
| Parameter group: | Security Arguments |
The marketplace image URN to use.
What happens to network interfaces when the VM is deleted. Use Delete or Detach for all NICs, or NAME=VALUE for individual NICs.
| Property | Value |
|---|---|
| Parameter group: | Network Arguments |
Names or resource IDs of existing network interfaces to attach. The first NIC is primary.
| Property | Value |
|---|---|
| Parameter group: | Network Arguments |
Name of the network security group to create (default: '{vm}NSG') or of an existing one to attach. Can also reference an existing NSG by resource ID, or specify "" for none.
| Property | Value |
|---|---|
| Parameter group: | Network Arguments |
Whether the OS disk is deleted or detached when the virtual machine is deleted.
Disk Encryption Set name or resource ID for customer-managed ConfidentialVM OS disk encryption.
| Property | Value |
|---|---|
| Parameter group: | Security Arguments |
Security encryption type for the OS managed disk. Required for ConfidentialVM.
| Property | Value |
|---|---|
| Parameter group: | Security Arguments |
| Accepted values: | VMGuestStateOnly, DiskWithVMGuestState, NonPersistedTPM |
Use the named profile for this command (overrides the active profile).
Name of the public IP address to create (default: '{vm}PublicIP') or of an existing one to attach. Can also reference an existing public IP by resource ID, or specify "" for none.
| Property | Value |
|---|---|
| Parameter group: | Network Arguments |
Security type for the virtual machine.
| Property | Value |
|---|---|
| Parameter group: | Security Arguments |
| Accepted values: | TrustedLaunch, ConfidentialVM, Standard |
Space-separated SSH public key values or public key file paths.
| Property | Value |
|---|---|
| Parameter group: | Authentication Arguments |
The storage SKU for the virtual machine's managed OS disk, such as Premium_LRS or StandardSSD_LRS.
Name or resource ID of the subnet for the new network interface.
| Property | Value |
|---|---|
| Parameter group: | Network Arguments |
Address prefixes for each subnet.
| Property | Value |
|---|---|
| Parameter group: | Network Arguments |
Names of the subnets.
| Property | Value |
|---|---|
| Parameter group: | Network Arguments |
Azure Subscription Id. Defaults to the active profile's subscription.
Space-separated tags in KEY=VALUE format, or a JSON object. Applied to the virtual machine and to every resource the command creates.
The virtual network name to create or use for a named subnet. Do not specify with --nics.
| Property | Value |
|---|---|
| Parameter group: | Network Arguments |
Availability zone for the virtual machine.
Global Parameters
Increase logging verbosity to show all debug logs.
Show help for the command or group and exit.
Bypass the extension discovery cache and reload extensions from disk.
Output format.
| Property | Value |
|---|---|
| Default value: | json |
| Accepted values: | json, jsonc, table, tsv, yaml, yamlc |
JMESPath query string to filter/project the command result before rendering.
az vm deallocate
Deallocate a virtual machine and release its compute resources.
Shut down a virtual machine and release its compute resources, so you are no longer billed for compute. Use az vm stop instead to power the machine off while keeping it allocated. Target a single VM with --name and --resource-group, or pass one or more full resource IDs to --ids to deallocate several VMs in one invocation. When --ids is used it supplies the subscription, resource group, and VM name for each target, so --name, --resource-group, and --subscription-id are ignored. Pass --hibernate to preserve the machine's memory state, or --force-deallocate to force the operation. The command waits for the long-running operation to finish and returns no output on success.
az vm deallocate [--force-deallocate]
[--hibernate]
[--ids]
[--name --vm-name]
[--profile]
[--resource-group]
[--subscription-id]
Examples
Deallocate a virtual machine
az vm deallocate --name myvm --resource-group myrg --subscription-id 00000000-0000-0000-0000-000000000000
Hibernate a virtual machine while deallocating it
az vm deallocate --name myvm --resource-group myrg --hibernate
Force deallocate a virtual machine
az vm deallocate --name myvm --resource-group myrg --force-deallocate
Deallocate several virtual machines by resource ID
az vm deallocate --ids /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myrg/providers/Microsoft.Compute/virtualMachines/myvm /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myrg/providers/Microsoft.Compute/virtualMachines/myothervm
Optional Parameters
The following parameters are optional, but depending on the context, one or more might become required for the command to execute successfully.
Force deallocate the virtual machine. Default is false.
Hibernate the virtual machine.
One or more virtual machine resource IDs. Provide either --ids or --name and --resource-group.
The name of the virtual machine.
Use the named profile for this command (overrides the active profile).
The resource group name.
Azure Subscription Id. Defaults to the active profile's subscription.
Global Parameters
Increase logging verbosity to show all debug logs.
Show help for the command or group and exit.
Bypass the extension discovery cache and reload extensions from disk.
Output format.
| Property | Value |
|---|---|
| Default value: | json |
| Accepted values: | json, jsonc, table, tsv, yaml, yamlc |
JMESPath query string to filter/project the command result before rendering.
az vm delete
Delete a virtual machine.
Remove the specified virtual machine from its resource group. The command deletes only the VM resource — attached disks, network interfaces, and the resource group itself are preserved and must be cleaned up separately if no longer required.
az vm delete [--force-deletion {0, 1, f, false, n, no, t, true, y, yes}]
[--ids]
[--name]
[--profile]
[--resource-group]
[--subscription-id]
Examples
Delete a virtual machine
az vm delete --name myvm --resource-group myrg --subscription-id 00000000-0000-0000-0000-000000000000
Delete using shell variables
az vm delete --name $vmName --resource-group $rg --subscription-id $subId
Optional Parameters
The following parameters are optional, but depending on the context, one or more might become required for the command to execute successfully.
Optional parameter to force delete virtual machines.
| Property | Value |
|---|---|
| Accepted values: | 0, 1, f, false, n, no, t, true, y, yes |
One or more virtual machine resource IDs. Provide either --ids or --name and --resource-group.
The name of the virtual machine.
Use the named profile for this command (overrides the active profile).
The resource group name.
Azure Subscription Id. Defaults to the active profile's subscription.
Global Parameters
Increase logging verbosity to show all debug logs.
Show help for the command or group and exit.
Bypass the extension discovery cache and reload extensions from disk.
Output format.
| Property | Value |
|---|---|
| Default value: | json |
| Accepted values: | json, jsonc, table, tsv, yaml, yamlc |
JMESPath query string to filter/project the command result before rendering.
az vm get-instance-view
Get instance information about a virtual machine.
Retrieve a virtual machine together with its run-time instance view, returned at properties.instanceView: the provisioning and power states, the VM agent, disks, extensions, boot diagnostics, and patch status. The command makes one request per virtual machine, so it is a quick way to check whether a VM is running, stopped, or deallocated.
az vm get-instance-view [--ids]
[--name]
[--profile]
[--resource-group]
[--subscription-id]
Examples
Get the instance view of a virtual machine
az vm get-instance-view --name myvm --resource-group myrg --subscription-id 00000000-0000-0000-0000-000000000000
Use the short option names
az vm get-instance-view -n myvm -g myrg
Get the instance views of several virtual machines by resource ID
az vm get-instance-view --ids /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myrg/providers/Microsoft.Compute/virtualMachines/myvm /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myrg/providers/Microsoft.Compute/virtualMachines/myvm2
Show only the power state
az vm get-instance-view -n myvm -g myrg --query "properties.instanceView.statuses[?starts_with(code, 'PowerState/')].displayStatus"
Optional Parameters
The following parameters are optional, but depending on the context, one or more might become required for the command to execute successfully.
One or more virtual machine resource IDs. Provide either --ids or --name and --resource-group.
The name of the virtual machine. Provide either --ids or --name and --resource-group.
Use the named profile for this command (overrides the active profile).
The resource group name. Provide either --ids or --name and --resource-group.
Azure Subscription Id. Defaults to the active profile's subscription.
Global Parameters
Increase logging verbosity to show all debug logs.
Show help for the command or group and exit.
Bypass the extension discovery cache and reload extensions from disk.
Output format.
| Property | Value |
|---|---|
| Default value: | json |
| Accepted values: | json, jsonc, table, tsv, yaml, yamlc |
JMESPath query string to filter/project the command result before rendering.
az vm list
List virtual machines.
Return a list of virtual machines, including each machine's name, size, location, and provisioning state. Omit --resource-group to list every virtual machine in the subscription. --show-details runs one extra request per virtual machine, so it is slow, and fetches details for at most 100 virtual machines. Use this command for inventory, audits, or before bulk operations such as start, stop, or delete.
az vm list [--profile]
[--resource-group]
[--show-details]
[--subscription-id]
[--vmss]
Examples
List all VMs in the subscription
az vm list --subscription-id 00000000-0000-0000-0000-000000000000
List VMs in a resource group
az vm list --resource-group myrg --subscription-id 00000000-0000-0000-0000-000000000000
List VM instances in a scale set by name
az vm list --resource-group myrg --vmss myvmss
List VM instances in a scale set by resource id
az vm list --vmss /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myrg/providers/Microsoft.Compute/virtualMachineScaleSets/myvmss
List VMs with public IP addresses, FQDNs and power states
az vm list --resource-group myrg -d
List using shell variables
az vm list --resource-group $rg --subscription-id $subId
Optional Parameters
The following parameters are optional, but depending on the context, one or more might become required for the command to execute successfully.
Use the named profile for this command (overrides the active profile).
The resource group name. Omit to list every virtual machine in the subscription.
Show public ip address, FQDN, and power states. Command will run slow.
Azure Subscription Id. Defaults to the active profile's subscription.
List VM instances in a specific VMSS. Please specify the VMSS id or VMSS name.
Global Parameters
Increase logging verbosity to show all debug logs.
Show help for the command or group and exit.
Bypass the extension discovery cache and reload extensions from disk.
Output format.
| Property | Value |
|---|---|
| Default value: | json |
| Accepted values: | json, jsonc, table, tsv, yaml, yamlc |
JMESPath query string to filter/project the command result before rendering.
az vm show
Show details for a virtual machine.
Retrieve the full property bag for the specified virtual machine, including hardware profile, OS profile, network interfaces, and provisioning state. Use this command to confirm a VM was created correctly or to inspect its current configuration.
az vm show [--ids]
[--include-user-data]
[--name]
[--profile]
[--resource-group]
[--show-details]
[--subscription-id]
Examples
Show a virtual machine by name
az vm show --name myvm --resource-group myrg --subscription-id 00000000-0000-0000-0000-000000000000
Show using shell variables
az vm show --name $vmName --resource-group $rg --subscription-id $subId
Show several virtual machines by resource ID
az vm show --ids /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myrg/providers/Microsoft.Compute/virtualMachines/myvm
Include the user data
az vm show --name myvm --resource-group myrg --include-user-data
Show public IPs, FQDNs and power state
az vm show --name myvm --resource-group myrg --show-details
Optional Parameters
The following parameters are optional, but depending on the context, one or more might become required for the command to execute successfully.
One or more virtual machine resource IDs. Provide either --ids or --name and --resource-group.
Include the user data properties in the query result.
The name of the virtual machine. Provide either --ids or --name and --resource-group.
Use the named profile for this command (overrides the active profile).
The resource group name. Provide either --ids or --name and --resource-group.
Show public ip address, FQDN, and power states. Command will run slow.
Azure Subscription Id. Defaults to the active profile's subscription.
Global Parameters
Increase logging verbosity to show all debug logs.
Show help for the command or group and exit.
Bypass the extension discovery cache and reload extensions from disk.
Output format.
| Property | Value |
|---|---|
| Default value: | json |
| Accepted values: | json, jsonc, table, tsv, yaml, yamlc |
JMESPath query string to filter/project the command result before rendering.
az vm start
Start a stopped virtual machine.
Power on a stopped or deallocated virtual machine. Target a single VM with --name and --resource-group, or pass one or more full resource IDs to --ids to start several VMs in one invocation. When --ids is used it supplies the subscription, resource group, and VM name for each target, so --name, --resource-group, and --subscription-id are ignored. The command waits for the long-running start operation to finish and returns no output on success.
az vm start [--ids]
[--name]
[--profile]
[--resource-group]
[--subscription-id]
Examples
Start a virtual machine
az vm start --name myvm --resource-group myrg --subscription-id 00000000-0000-0000-0000-000000000000
Start using shell variables
az vm start --name $vmName --resource-group $rg --subscription-id $subId
Start several virtual machines by resource ID
az vm start --ids /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myrg/providers/Microsoft.Compute/virtualMachines/myvm /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myrg/providers/Microsoft.Compute/virtualMachines/myothervm
Optional Parameters
The following parameters are optional, but depending on the context, one or more might become required for the command to execute successfully.
One or more virtual machine resource IDs. Provide either --ids or --name and --resource-group.
The name of the virtual machine.
Use the named profile for this command (overrides the active profile).
The resource group name.
Azure Subscription Id. Defaults to the active profile's subscription.
Global Parameters
Increase logging verbosity to show all debug logs.
Show help for the command or group and exit.
Bypass the extension discovery cache and reload extensions from disk.
Output format.
| Property | Value |
|---|---|
| Default value: | json |
| Accepted values: | json, jsonc, table, tsv, yaml, yamlc |
JMESPath query string to filter/project the command result before rendering.
az vm stop
Power off (stop) a running virtual machine.
Power off a running virtual machine while leaving its compute resources allocated. The virtual machine continues to be billed; use az vm deallocate to release the compute resources and stop compute charges. Target a single VM with --name and --resource-group, or pass one or more full resource IDs to --ids to power off several VMs in one invocation. When --ids is used it supplies the subscription, resource group, and VM name for each target, so --name, --resource-group, and --subscription-id are ignored. Pass --skip-shutdown to power the machine off immediately instead of requesting a graceful guest shutdown. The command waits for the long-running operation to finish and returns no output on success.
az vm stop [--ids]
[--name --vm-name]
[--profile]
[--resource-group]
[--skip-shutdown]
[--subscription-id]
Examples
Power off a running virtual machine
az vm stop --name myvm --resource-group myrg --subscription-id 00000000-0000-0000-0000-000000000000
Power off a virtual machine without shutting down
az vm stop --name myvm --resource-group myrg --skip-shutdown
Power off several virtual machines by resource ID
az vm stop --ids /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myrg/providers/Microsoft.Compute/virtualMachines/myvm /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myrg/providers/Microsoft.Compute/virtualMachines/myothervm
Optional Parameters
The following parameters are optional, but depending on the context, one or more might become required for the command to execute successfully.
One or more virtual machine resource IDs. Provide either --ids or --name and --resource-group.
The name of the virtual machine.
Use the named profile for this command (overrides the active profile).
The resource group name.
Skip shutdown and power off immediately.
Azure Subscription Id. Defaults to the active profile's subscription.
Global Parameters
Increase logging verbosity to show all debug logs.
Show help for the command or group and exit.
Bypass the extension discovery cache and reload extensions from disk.
Output format.
| Property | Value |
|---|---|
| Default value: | json |
| Accepted values: | json, jsonc, table, tsv, yaml, yamlc |
JMESPath query string to filter/project the command result before rendering.