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
idstringResource Id
namestringResource name
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.
extendedLocationobjectThe extended location of the Virtual Machine.
identityobjectThe identity of the virtual machine, if configured.
locationstringResource location
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.
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.
propertiesobjectDescribes the properties of a Virtual Machine.
resourcesarrayThe virtual machine child extension resources.
tagsobjectResource tags
typestringResource type
zonesarrayThe virtual machine zones.

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
getselectresourceGroupName, vmName, subscriptionId$expandRetrieves information about the model view or the instance view of a virtual machine.
list_by_locationselectlocation, subscriptionIdGets all the virtual machines under the specified subscription for the specified location.
listselectresourceGroupName, subscriptionId$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_allselectsubscriptionIdstatusOnly, $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_updateinsertresourceGroupName, vmName, subscriptionIdIf-Match, If-None-MatchThe operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
updateupdateresourceGroupName, vmName, subscriptionIdIf-Match, If-None-MatchThe operation to update a virtual machine.
deletedeleteresourceGroupName, vmName, subscriptionIdforceDeletionThe operation to delete a virtual machine.
run_commandexecresourceGroupName, vmName, subscriptionId, commandIdRun command on the VM.
captureexecresourceGroupName, vmName, subscriptionId, 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.
instance_viewexecresourceGroupName, vmName, subscriptionIdRetrieves information about the run-time state of a virtual machine.
convert_to_managed_disksexecresourceGroupName, vmName, subscriptionIdConverts virtual machine disks from blob-based to managed disks. Virtual machine must be stop-deallocated before invoking this operation.
deallocateexecresourceGroupName, vmName, subscriptionIdhibernateShuts down the virtual machine and releases the compute resources. You are not billed for the compute resources that this virtual machine uses.
generalizeexecresourceGroupName, vmName, subscriptionIdSets 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.
power_offexecresourceGroupName, vmName, subscriptionIdskipShutdownThe 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.
reapplyexecresourceGroupName, vmName, subscriptionIdThe operation to reapply a virtual machine's state.
restartexecresourceGroupName, vmName, subscriptionIdThe operation to restart a virtual machine.
startexecresourceGroupName, vmName, subscriptionIdThe operation to start a virtual machine.
redeployexecresourceGroupName, vmName, subscriptionIdShuts down the virtual machine, moves it to a new node, and powers it back on.
reimageexecresourceGroupName, vmName, subscriptionIdReimages (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.
retrieve_boot_diagnostics_dataexecresourceGroupName, vmName, subscriptionIdsasUriExpirationTimeInMinutesThe operation to retrieve SAS URIs for a virtual machine's boot diagnostic logs.
perform_maintenanceexecresourceGroupName, vmName, subscriptionIdThe operation to perform maintenance on a virtual machine.
simulate_evictionexecresourceGroupName, vmName, subscriptionIdThe operation to simulate the eviction of spot virtual machine.
assess_patchesexecresourceGroupName, vmName, subscriptionIdAssess patches on the VM.
install_patchesexecresourceGroupName, vmName, subscriptionId, rebootSettingInstalls patches on the VM.
attach_detach_data_disksexecresourceGroupName, vmName, subscriptionIdAttach and detach data disks to/from the virtual machine.

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 for which virtual machines under the subscription are queried.
resourceGroupNamestringThe name of the resource group.
subscriptionIdstringSubscription credentials which uniquely identify Microsoft Azure subscription. The subscription ID forms part of the URI for every service call.
vmNamestringThe name of the virtual machine.
$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
$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}'
If-MatchstringThe ETag of the transformation. Omit this value to always overwrite the current resource. Specify the last-seen ETag value to prevent accidentally overwriting concurrent changes.
If-None-MatchstringSet to '*' to allow a new record set to be created, but to prevent updating an existing record set. Other values will result in error from server as they are not supported.
forceDeletionbooleanOptional parameter to force delete virtual machines.
hibernatebooleanOptional parameter to hibernate a virtual machine.
sasUriExpirationTimeInMinutesinteger (int32)Expiration 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.
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
statusOnlystringstatusOnly=true enables fetching run time status of all Virtual Machines in the subscription.

SELECT examples

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

SELECT
id,
name,
etag,
extendedLocation,
identity,
location,
managedBy,
plan,
properties,
resources,
tags,
type,
zones
FROM azure.compute.virtual_machines
WHERE resourceGroupName = '{{ resourceGroupName }}' -- required
AND vmName = '{{ vmName }}' -- required
AND subscriptionId = '{{ subscriptionId }}' -- 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 (
data__plan,
data__properties,
data__identity,
data__zones,
data__extendedLocation,
data__location,
data__tags,
resourceGroupName,
vmName,
subscriptionId,
If-Match,
If-None-Match
)
SELECT
'{{ plan }}',
'{{ properties }}',
'{{ identity }}',
'{{ zones }}',
'{{ extendedLocation }}',
'{{ location }}',
'{{ tags }}',
'{{ resourceGroupName }}',
'{{ vmName }}',
'{{ subscriptionId }}',
'{{ If-Match }}',
'{{ If-None-Match }}'
RETURNING
id,
name,
etag,
extendedLocation,
identity,
location,
managedBy,
plan,
properties,
resources,
tags,
type,
zones
;

UPDATE examples

The operation to update a virtual machine.

UPDATE azure.compute.virtual_machines
SET
data__plan = '{{ plan }}',
data__properties = '{{ properties }}',
data__identity = '{{ identity }}',
data__zones = '{{ zones }}',
data__tags = '{{ tags }}'
WHERE
resourceGroupName = '{{ resourceGroupName }}' --required
AND vmName = '{{ vmName }}' --required
AND subscriptionId = '{{ subscriptionId }}' --required
AND If-Match = '{{ If-Match}}'
AND If-None-Match = '{{ If-None-Match}}'
RETURNING
id,
name,
etag,
extendedLocation,
identity,
location,
managedBy,
plan,
properties,
resources,
tags,
type,
zones;

DELETE examples

The operation to delete a virtual machine.

DELETE FROM azure.compute.virtual_machines
WHERE resourceGroupName = '{{ resourceGroupName }}' --required
AND vmName = '{{ vmName }}' --required
AND subscriptionId = '{{ subscriptionId }}' --required
AND forceDeletion = '{{ forceDeletion }}'
;

Lifecycle Methods

Run command on the VM.

EXEC azure.compute.virtual_machines.run_command 
@resourceGroupName='{{ resourceGroupName }}' --required,
@vmName='{{ vmName }}' --required,
@subscriptionId='{{ subscriptionId }}' --required
@@json=
'{
"commandId": "{{ commandId }}",
"script": "{{ script }}",
"parameters": "{{ parameters }}"
}'
;