Skip to main content

virtual_machines

Creates, updates, deletes, gets or lists a virtual_machines resource.

Overview

Namevirtual_machines
TypeResource
Idazure.compute.virtual_machines

Fields

The following fields are returned by SELECT queries:

NameDatatypeDescription
idstringFully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}.
namestringThe name of the resource.
additionalCapabilitiesobjectSpecifies additional capabilities enabled or disabled on the virtual machine.
applicationProfileobjectSpecifies the gallery applications that should be made available to the VM/VMSS.
availabilitySetobjectSubResource.
billingProfileobjectSpecifies the billing related details of a Azure Spot virtual machine. Minimum api-version: 2019-03-01.
capacityReservationobjectSpecifies information about the capacity reservation that is used to allocate virtual machine. Minimum api-version: 2021-04-01.
diagnosticsProfileobjectSpecifies the boot diagnostic settings state. Minimum api-version: 2015-06-15.
etagstringEtag is property returned in Create/Update/Get response of the VM, so that customer can supply it in the header to ensure optimistic updates.
evictionPolicystringSpecifies the eviction policy for the Azure Spot virtual machine and Azure Spot scale set. For Azure Spot virtual machines, both 'Deallocate' and 'Delete' are supported and the minimum api-version is 2019-03-01. For Azure Spot scale sets, both 'Deallocate' and 'Delete' are supported and the minimum api-version is 2017-10-30-preview. Known values are: "Deallocate" and "Delete". (Deallocate, Delete)
extendedLocationobjectThe extended location of the Virtual Machine.
extensionsTimeBudgetstringSpecifies the time alloted for all extensions to start. The time duration should be between 15 minutes and 120 minutes (inclusive) and should be specified in ISO 8601 format. The default value is 90 minutes (PT1H30M). Minimum api-version: 2020-06-01.
hardwareProfileobjectSpecifies the hardware settings for the virtual machine.
hostobjectSubResource.
hostGroupobjectSubResource.
identityobjectThe identity of the virtual machine, if configured.
instanceViewobjectThe virtual machine instance view.
interconnectBlockProfileobjectSpecifies information about the Interconnect Block that is used to allocate the Virtual Machine. Minimum api-version: 2026-03-01.
licenseTypestringSpecifies that the image or disk that is being used was licensed on-premises. Possible values for Windows Server operating system are: Windows_Client Windows_Server Possible values for Linux Server operating system are: RHEL_BYOS (for RHEL) SLES_BYOS (for SUSE) For more information, see Azure Hybrid Use Benefit for Windows Server _ Azure Hybrid Use Benefit for Linux Server _ Minimum api-version: 2015-06-15.
locationstringThe geo-location where the resource lives. Required.
managedBystringManagedBy is set to Virtual Machine Scale Set(VMSS) flex ARM resourceID, if the VM is part of the VMSS. This property is used by platform for internal resource group delete optimization.
networkProfileobjectSpecifies the network interfaces of the virtual machine.
osProfileobjectSpecifies the operating system settings used while creating the virtual machine. Some of the settings cannot be changed once VM is provisioned.
placementobjectPlacement section specifies the user-defined constraints for virtual machine hardware placement. This property cannot be changed once VM is provisioned. Minimum api-version: 2024-11-01.
planobjectSpecifies information about the marketplace image used to create the virtual machine. This element is only used for marketplace images. Before you can use a marketplace image from an API, you must enable the image for programmatic use. In the Azure portal, find the marketplace image that you want to use and then click Want to deploy programmatically, Get Started ->. Enter any required information and then click Save.
platformFaultDomainintegerSpecifies the scale set logical fault domain into which the Virtual Machine will be created. By default, the Virtual Machine will by automatically assigned to a fault domain that best maintains balance across available fault domains. This is applicable only if the 'virtualMachineScaleSet' property of this Virtual Machine is set. The Virtual Machine Scale Set that is referenced, must have 'platformFaultDomainCount' greater than 1. This property cannot be updated once the Virtual Machine is created. Fault domain assignment can be viewed in the Virtual Machine Instance View. Minimum api‐version: 2020‐12‐01.
prioritystringSpecifies the priority for the virtual machine. Minimum api-version: 2019-03-01. Known values are: "Regular", "Low", and "Spot". (Regular, Low, Spot)
provisioningStatestringThe provisioning state, which only appears in the response.
proximityPlacementGroupobjectSubResource.
resiliencyProfileobjectResiliency profile for the virtual machine.
resourcesarrayThe virtual machine child extension resources.
scheduledEventsPolicyobjectSpecifies Redeploy, Reboot and ScheduledEventsAdditionalPublishingTargets Scheduled Event related configurations for the virtual machine.
scheduledEventsProfileobjectSpecifies Scheduled Event related configurations.
securityProfileobjectSpecifies the Security related profile settings for the virtual machine.
storageProfileobjectSpecifies the storage settings for the virtual machine disks.
systemDataobjectAzure Resource Manager metadata containing createdBy and modifiedBy information.
tagsobjectResource tags.
timeCreatedstring (date-time)Specifies the time at which the Virtual Machine resource was created. Minimum api-version: 2021-11-01.
typestringThe type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts".
userDatastringUserData for the VM, which must be base-64 encoded. Customer should not pass any secrets in here. Minimum api-version: 2021-03-01.
virtualMachineScaleSetobjectSubResource.
vmIdstringSpecifies the VM unique ID which is a 128-bits identifier that is encoded and stored in all Azure IaaS VMs SMBIOS and can be read using platform BIOS commands.
zonesarrayThe availability zones.

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
getselectresource_group_name, vm_name, subscription_id$expandRetrieves information about the model view or the instance view of a virtual machine.
listselectresource_group_name, subscription_id$filter, $expandLists all of the virtual machines in the specified resource group. Use the nextLink property in the response to get the next page of virtual machines.
list_by_locationselectlocation, subscription_idGets all the virtual machines under the specified subscription for the specified location.
list_allselectsubscription_idstatusOnly, $filter, $expandLists all of the virtual machines in the specified subscription. Use the nextLink property in the response to get the next page of virtual machines.
create_or_updateinsertresource_group_name, vm_name, subscription_id, locationThe operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
updateupdateresource_group_name, vm_name, subscription_idThe operation to update a virtual machine.
create_or_updatereplaceresource_group_name, vm_name, subscription_id, locationThe operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
deletedeleteresource_group_name, vm_name, subscription_idforceDeletionThe operation to delete a virtual machine.
list_available_sizesexecresource_group_name, vm_name, subscription_idLists all available virtual machine sizes to which the specified virtual machine can be resized.
assess_patchesexecresource_group_name, vm_name, subscription_idAssess patches on the VM.
attach_detach_data_disksexecresource_group_name, vm_name, subscription_idAttach and detach data disks to/from the virtual machine.
captureexecresource_group_name, vm_name, subscription_id, vhdPrefix, destinationContainerName, overwriteVhdsCaptures the VM by copying virtual hard disks of the VM and outputs a template that can be used to create similar VMs.
convert_to_managed_disksexecresource_group_name, vm_name, subscription_idConverts virtual machine disks from blob-based to managed disks. Virtual machine must be stop-deallocated before invoking this operation.
deallocateexecresource_group_name, vm_name, subscription_idhibernate, forceDeallocateShuts down the virtual machine and releases the compute resources. You are not billed for the compute resources that this virtual machine uses.
generalizeexecresource_group_name, vm_name, subscription_idSets the OS state of the virtual machine to generalized. It is recommended to sysprep the virtual machine before performing this operation. For Windows, please refer to Create a managed image of a generalized VM in Azure . For Linux, please refer to How to create an image of a virtual machine or VHD .
install_patchesexecresource_group_name, vm_name, subscription_id, rebootSettingInstalls patches on the VM.
instance_viewexecresource_group_name, vm_name, subscription_idRetrieves information about the run-time state of a virtual machine.
perform_maintenanceexecresource_group_name, vm_name, subscription_idThe operation to perform maintenance on a virtual machine.
power_offexecresource_group_name, vm_name, subscription_idskipShutdownThe operation to power off (stop) a virtual machine. The virtual machine can be restarted with the same provisioned resources. You are still charged for this virtual machine.
reapplyexecresource_group_name, vm_name, subscription_idThe operation to reapply a virtual machine's state.
redeployexecresource_group_name, vm_name, subscription_idShuts down the virtual machine, moves it to a new node, and powers it back on.
reimageexecresource_group_name, vm_name, subscription_idReimages (upgrade the operating system) a virtual machine which don't have a ephemeral OS disk, for virtual machines who have a ephemeral OS disk the virtual machine is reset to initial state. NOTE: The retaining of old OS disk depends on the value of deleteOption of OS disk. If deleteOption is detach, the old OS disk will be preserved after reimage. If deleteOption is delete, the old OS disk will be deleted after reimage. The deleteOption of the OS disk should be updated accordingly before performing the reimage.
restartexecresource_group_name, vm_name, subscription_idThe operation to restart a virtual machine.
retrieve_boot_diagnostics_dataexecresource_group_name, vm_name, subscription_idsasUriExpirationTimeInMinutesThe operation to retrieve SAS URIs for a virtual machine's boot diagnostic logs.
simulate_evictionexecresource_group_name, vm_name, subscription_idThe operation to simulate the eviction of spot virtual machine.
startexecresource_group_name, vm_name, subscription_idThe operation to start a virtual machine.
run_commandexecresource_group_name, vm_name, subscription_id, commandIdRun command on the VM.
migrate_to_vm_scale_setexecresource_group_name, vm_name, subscription_idMigrate a virtual machine from availability set to Flexible Virtual Machine Scale Set.

Parameters

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
locationstringThe location name. Required.
resource_group_namestringThe name of the resource group. The name is case insensitive. Required.
subscription_idstring
vm_namestringThe name of the virtual machine. Required.
$expandstringThe expand expression to apply on operation. 'instanceView' enables fetching run time status of all Virtual Machines, this can only be specified if a valid $filter option is specified. "instanceView" Default value is None.
$filterstringThe system query option to filter VMs returned in the response. Allowed value is 'virtualMachineScaleSet/id' eq /subscriptions/{subId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmssName}'. Default value is None.
forceDeallocatebooleanOptional parameter to force deallocate a virtual machine. Default is false. Default value is None.
forceDeletionbooleanOptional parameter to force delete virtual machines. Default value is None.
hibernatebooleanOptional parameter to hibernate a virtual machine. Default value is None.
sasUriExpirationTimeInMinutesintegerExpiration duration in minutes for the SAS URIs with a value between 1 to 1440 minutes. Note: If not specified, SAS URIs will be generated with a default expiration duration of 120 minutes. Default value is None.
skipShutdownbooleanThe parameter to request non-graceful VM shutdown. True value for this flag indicates non-graceful shutdown whereas false indicates otherwise. Default value for this flag is false if not specified. Default value is None.
statusOnlystringstatusOnly=true enables fetching run time status of all Virtual Machines in the subscription. Default value is None.

SELECT examples

Retrieves information about the model view or the instance view of a virtual machine.

SELECT
id,
name,
additionalCapabilities,
applicationProfile,
availabilitySet,
billingProfile,
capacityReservation,
diagnosticsProfile,
etag,
evictionPolicy,
extendedLocation,
extensionsTimeBudget,
hardwareProfile,
host,
hostGroup,
identity,
instanceView,
interconnectBlockProfile,
licenseType,
location,
managedBy,
networkProfile,
osProfile,
placement,
plan,
platformFaultDomain,
priority,
provisioningState,
proximityPlacementGroup,
resiliencyProfile,
resources,
scheduledEventsPolicy,
scheduledEventsProfile,
securityProfile,
storageProfile,
systemData,
tags,
timeCreated,
type,
userData,
virtualMachineScaleSet,
vmId,
zones
FROM azure.compute.virtual_machines
WHERE resource_group_name = '{{ resource_group_name }}' -- required
AND vm_name = '{{ vm_name }}' -- required
AND subscription_id = '{{ subscription_id }}' -- required
AND $expand = '{{ $expand }}'
;

INSERT examples

The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.

INSERT INTO azure.compute.virtual_machines (
tags,
location,
properties,
plan,
identity,
zones,
extendedLocation,
placement,
resource_group_name,
vm_name,
subscription_id
)
SELECT
'{{ tags }}',
'{{ location }}' /* required */,
'{{ properties }}',
'{{ plan }}',
'{{ identity }}',
'{{ zones }}',
'{{ extendedLocation }}',
'{{ placement }}',
'{{ resource_group_name }}',
'{{ vm_name }}',
'{{ subscription_id }}'
RETURNING
id,
name,
etag,
extendedLocation,
identity,
location,
managedBy,
placement,
plan,
properties,
resources,
systemData,
tags,
type,
zones
;

UPDATE examples

The operation to update a virtual machine.

UPDATE azure.compute.virtual_machines
SET
tags = '{{ tags }}',
plan = '{{ plan }}',
properties = '{{ properties }}',
identity = '{{ identity }}',
zones = '{{ zones }}'
WHERE
resource_group_name = '{{ resource_group_name }}' --required
AND vm_name = '{{ vm_name }}' --required
AND subscription_id = '{{ subscription_id }}' --required
RETURNING
id,
name,
etag,
extendedLocation,
identity,
location,
managedBy,
placement,
plan,
properties,
resources,
systemData,
tags,
type,
zones;

REPLACE examples

The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.

REPLACE azure.compute.virtual_machines
SET
tags = '{{ tags }}',
location = '{{ location }}',
properties = '{{ properties }}',
plan = '{{ plan }}',
identity = '{{ identity }}',
zones = '{{ zones }}',
extendedLocation = '{{ extendedLocation }}',
placement = '{{ placement }}'
WHERE
resource_group_name = '{{ resource_group_name }}' --required
AND vm_name = '{{ vm_name }}' --required
AND subscription_id = '{{ subscription_id }}' --required
AND location = '{{ location }}' --required
RETURNING
id,
name,
etag,
extendedLocation,
identity,
location,
managedBy,
placement,
plan,
properties,
resources,
systemData,
tags,
type,
zones;

DELETE examples

The operation to delete a virtual machine.

DELETE FROM azure.compute.virtual_machines
WHERE resource_group_name = '{{ resource_group_name }}' --required
AND vm_name = '{{ vm_name }}' --required
AND subscription_id = '{{ subscription_id }}' --required
AND forceDeletion = '{{ forceDeletion }}'
;

Lifecycle Methods

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

EXEC azure.compute.virtual_machines.list_available_sizes 
@resource_group_name='{{ resource_group_name }}' --required,
@vm_name='{{ vm_name }}' --required,
@subscription_id='{{ subscription_id }}' --required
;