De bewerking voor het maken of bijwerken van een virtuele machine. Houd er rekening mee dat sommige eigenschappen alleen kunnen worden ingesteld tijdens het maken van virtuele machines.
PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}?api-version=2026-04-01
URI-parameters
| Name |
In |
Vereist |
Type |
Description |
|
resourceGroupName
|
path |
True
|
string
minLength: 1 maxLength: 90
|
De naam van de resource group. De naam is hoofdletterongevoelig.
|
|
subscriptionId
|
path |
True
|
string
minLength: 1
|
De ID van het doelabonnement.
|
|
vmName
|
path |
True
|
string
|
De naam van de virtuele machine.
|
|
api-version
|
query |
True
|
string
minLength: 1
|
De API-versie die voor deze bewerking moet worden gebruikt.
|
| Name |
Vereist |
Type |
Description |
|
If-Match
|
|
string
|
De ETag van de transformatie. Laat deze waarde weg om de huidige resource altijd te overschrijven. Geef de laatst geziene ETag-waarde op om te voorkomen dat gelijktijdige wijzigingen per ongeluk worden overschreven.
|
|
If-None-Match
|
|
string
|
Stel deze optie in op *, zodat een nieuwe recordset kan worden gemaakt, maar om te voorkomen dat een bestaande recordset wordt bijgewerkt. Andere waarden resulteren in een fout van de server omdat ze niet worden ondersteund.
|
Aanvraagbody
| Name |
Vereist |
Type |
Description |
|
location
|
True
|
string
|
De geografische locatie waar de resource zich bevindt
|
|
extendedLocation
|
|
ExtendedLocation
|
De uitgebreide locatie van de virtuele machine.
|
|
identity
|
|
VirtualMachineIdentity
|
De identiteit van de virtuele machine, indien geconfigureerd.
|
|
placement
|
|
Placement
|
In de sectie Plaatsing worden de door de gebruiker gedefinieerde beperkingen opgegeven voor de plaatsing van hardware van virtuele machines. Deze eigenschap kan niet worden gewijzigd zodra de VM is ingericht. Minimale API-versie: 2024-11-01.
|
|
plan
|
|
Plan
|
Hiermee geeft u informatie op over de marketplace-installatiekopieën die worden gebruikt om de virtuele machine te maken. Dit element wordt alleen gebruikt voor Marketplace-installatiekopieën. Voordat u een Marketplace-installatiekopieën van een API kunt gebruiken, moet u de installatiekopieën inschakelen voor programmatisch gebruik. Zoek in Azure Portal de marketplace-installatiekopieën die u wilt gebruiken en klik vervolgens op Programmatisch wilt implementeren, Aan de slag ->. Voer de vereiste gegevens in en klik vervolgens op Opslaan.
|
|
properties.additionalCapabilities
|
|
AdditionalCapabilities
|
Hiermee geeft u aanvullende mogelijkheden op die zijn ingeschakeld of uitgeschakeld op de virtuele machine.
|
|
properties.applicationProfile
|
|
ApplicationProfile
|
Hiermee geeft u de galerietoepassingen op die beschikbaar moeten worden gesteld voor de VM/VMSS.
|
|
properties.availabilitySet
|
|
SubResource
|
Hiermee geeft u informatie op over de beschikbaarheidsset waaraan de virtuele machine moet worden toegewezen. Virtuele machines die zijn opgegeven in dezelfde beschikbaarheidsset, worden toegewezen aan verschillende knooppunten om de beschikbaarheid te maximaliseren. Zie Overzicht van beschikbaarheidssetsvoor meer informatie over beschikbaarheidssets. Zie Onderhoud en updates voor virtuele machines in Azurevoor meer informatie over gepland azure-onderhoud. Op dit moment kan een VIRTUELE machine alleen worden toegevoegd aan de beschikbaarheidsset tijdens het maken. De beschikbaarheidsset waaraan de VIRTUELE machine wordt toegevoegd, moet zich onder dezelfde resourcegroep bevinden als de resource van de beschikbaarheidsset. Een bestaande VM kan niet worden toegevoegd aan een beschikbaarheidsset. Deze eigenschap kan niet samen met een verwijzing naar niet-null properties.virtualMachineScaleSet bestaan.
|
|
properties.billingProfile
|
|
BillingProfile
|
Hiermee geeft u de factureringsgerelateerde details van een virtuele Azure Spot-machine op. Minimale API-versie: 2019-03-01.
|
|
properties.capacityReservation
|
|
CapacityReservationProfile
|
Hiermee geeft u informatie op over de capaciteitsreservering die wordt gebruikt om virtuele machine toe te wijzen. Minimale API-versie: 2021-04-01.
|
|
properties.diagnosticsProfile
|
|
DiagnosticsProfile
|
Hiermee geeft u de status van diagnostische instellingen voor opstarten. Minimale API-versie: 2015-06-15.
|
|
properties.evictionPolicy
|
|
VirtualMachineEvictionPolicyTypes
|
Hiermee geeft u het verwijderingsbeleid voor de virtuele Azure Spot-machine en Azure Spot-schaalset op. Voor virtuele Azure Spot-machines worden zowel Toewijzing ongedaan maken als Verwijderen ondersteund en is de minimale API-versie 2019-03-01. Voor Azure Spot-schaalsets worden zowel 'Toewijzing ongedaan maken' als 'Verwijderen' ondersteund en is de minimale API-versie 2017-10-30-preview.
|
|
properties.extensionsTimeBudget
|
|
string
|
Hiermee geeft u de tijd die is toegewezen voor alle extensies die moeten worden gestart. De tijdsduur moet liggen tussen 15 minuten en 120 minuten (inclusief) en moet worden opgegeven in ISO 8601-indeling. De standaardwaarde is 90 minuten (PT1H30M). Minimale API-versie: 2020-06-01.
|
|
properties.hardwareProfile
|
|
HardwareProfile
|
Hiermee geeft u de hardware-instellingen voor de virtuele machine.
|
|
properties.host
|
|
SubResource
|
Hiermee geeft u informatie op over de toegewezen host waarin de virtuele machine zich bevindt. Minimale API-versie: 2018-10-01.
|
|
properties.hostGroup
|
|
SubResource
|
Hiermee geeft u informatie op over de toegewezen hostgroep waarin de virtuele machine zich bevindt.
Opmerking: gebruiker kan de eigenschappen host en hostGroup niet opgeven. Minimale API-versie: 2020-06-01.
|
|
properties.interconnectBlockProfile
|
|
InterconnectBlockProfile
|
Specificeert informatie over het Interconnect Block dat wordt gebruikt om de Virtual Machine toe te wijzen. Minimale api-versie: 2026-03-01.
|
|
properties.licenseType
|
|
string
|
Hiermee geeft u op dat de installatiekopieën of schijven die worden gebruikt, on-premises zijn gelicentieerd.
Mogelijke waarden voor het Windows Server-besturingssysteem zijn:
Windows_Client
Windows_Server
Mogelijke waarden voor het Linux Server-besturingssysteem zijn:
RHEL_BYOS (voor RHEL)
SLES_BYOS (voor SUSE)
Zie Azure Hybrid Use Benefit voor Windows Server voor meer informatie
Azure Hybrid Use Benefit voor Linux Server-
Minimale API-versie: 2015-06-15
|
|
properties.networkProfile
|
|
NetworkProfile
|
Hiermee geeft u de netwerkinterfaces van de virtuele machine.
|
|
properties.osProfile
|
|
OSProfile
|
Hiermee geeft u de instellingen van het besturingssysteem op die worden gebruikt tijdens het maken van de virtuele machine. Sommige instellingen kunnen niet worden gewijzigd zodra de VIRTUELE machine is ingericht.
|
|
properties.platformFaultDomain
|
|
integer
(int32)
|
Hiermee geeft u het logische foutdomein van de schaalset waarin de virtuele machine wordt gemaakt. De virtuele machine wordt standaard automatisch toegewezen aan een foutdomein dat de beste balans behoudt tussen beschikbare foutdomeinen. Dit is alleen van toepassing als de eigenschap virtualMachineScaleSet van deze virtuele machine is ingesteld. De virtuele-machineschaalset waarnaar wordt verwezen, moet 'platformFaultDomainCount' groter dan 1 hebben. Deze eigenschap kan niet worden bijgewerkt zodra de virtuele machine is gemaakt. Foutdomeintoewijzing kan worden weergegeven in de weergave exemplaar van de virtuele machine. Minimale API-versie: 2020-12-01.
|
|
properties.priority
|
|
VirtualMachinePriorityTypes
|
Hiermee geeft u de prioriteit voor de virtuele machine. Minimale API-versie: 2019-03-01
|
|
properties.proximityPlacementGroup
|
|
SubResource
|
Hiermee geeft u informatie op over de nabijheidsplaatsingsgroep waaraan de virtuele machine moet worden toegewezen. Minimale API-versie: 2018-04-01.
|
|
properties.resiliencyProfile
|
|
ResiliencyProfile
|
Veerkrachtprofiel voor de virtuele machine.
|
|
properties.scheduledEventsPolicy
|
|
ScheduledEventsPolicy
|
Hiermee geeft u configuraties met betrekking tot geplande gebeurtenissen opnieuw implementeren, opnieuw opstarten en ScheduledEventsAdditionalPublishingTargets Scheduled Event voor de virtuele machine.
|
|
properties.scheduledEventsProfile
|
|
ScheduledEventsProfile
|
Hiermee geeft u configuraties met betrekking tot geplande gebeurtenissen op.
|
|
properties.securityProfile
|
|
SecurityProfile
|
Hiermee geeft u de beveiligingsgerelateerde profielinstellingen voor de virtuele machine.
|
|
properties.storageProfile
|
|
StorageProfile
|
Hiermee geeft u de opslaginstellingen voor de schijven van de virtuele machine op.
|
|
properties.userData
|
|
string
|
UserData voor de VIRTUELE machine, die base-64 moet zijn gecodeerd. De klant mag hier geen geheimen doorgeven. Minimale API-versie: 2021-03-01.
|
|
properties.virtualMachineScaleSet
|
|
SubResource
|
Hiermee geeft u informatie op over de virtuele-machineschaalset waaraan de virtuele machine moet worden toegewezen. Virtuele machines die zijn opgegeven in dezelfde virtuele-machineschaalset, worden toegewezen aan verschillende knooppunten om de beschikbaarheid te maximaliseren. Op dit moment kan een VIRTUELE machine alleen worden toegevoegd aan een virtuele-machineschaalset tijdens het maken. Een bestaande VM kan niet worden toegevoegd aan een virtuele-machineschaalset. Deze eigenschap kan niet bestaan samen met een verwijzing naar niet-null properties.availabilitySet. Minimale API-versie: 2019-03-01.
|
|
tags
|
|
object
|
Resourcetags.
|
|
zones
|
|
string[]
|
De beschikbaarheidszones.
|
Antwoorden
| Name |
Type |
Description |
|
200 OK
|
VirtualMachine
|
Resource 'VirtualMachine'-updatebewerking geslaagd
|
|
201 Created
|
VirtualMachine
|
Resource 'VirtualMachine' create operatie geslaagd
Kopteksten
- Location: string
- Retry-After: integer
|
|
Other Status Codes
|
CloudError
|
Een onverwachte foutreactie.
|
Beveiliging
azure_auth
OAuth2-stroom voor Azure Active Directory.
Type:
oauth2
Stroom:
implicit
Autorisatie-URL:
https://login.microsoftonline.com/common/oauth2/authorize
Bereiken
| Name |
Description |
|
user_impersonation
|
Uw gebruikersaccount imiteren
|
Voorbeelden
Create a custom-image vm from an unmanaged generalized os image.
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/{vm-name}?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"osDisk": {
"name": "myVMosdisk",
"image": {
"uri": "http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/{existing-generalized-os-image-blob-name}.vhd"
},
"osType": "Windows",
"createOption": "FromImage",
"caching": "ReadWrite",
"vhd": {
"uri": "http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk.vhd"
}
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.OperatingSystemTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualHardDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* 2026-04-01/virtualMachineExamples/VirtualMachine_Create_CustomImageVmFromAnUnmanagedGeneralizedOsImage.json
*/
/**
* Sample code: Create a custom-image vm from an unmanaged generalized os image.
*
* @param manager Entry point to ComputeManager.
*/
public static void createACustomImageVmFromAnUnmanagedGeneralizedOsImage(
com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "{vm-name}",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withOsDisk(new OSDisk()
.withOsType(OperatingSystemTypes.WINDOWS).withName("myVMosdisk")
.withVhd(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk.vhd"))
.withImage(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/{existing-generalized-os-image-blob-name}.vhd"))
.withCaching(CachingTypes.READ_WRITE).withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_custom_image_vm_from_an_unmanaged_generalized_os_image.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="{vm-name}",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"image": {
"uri": "http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/{existing-generalized-os-image-blob-name}.vhd"
},
"name": "myVMosdisk",
"osType": "Windows",
"vhd": {
"uri": "http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk.vhd"
},
}
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_CustomImageVmFromAnUnmanagedGeneralizedOsImage.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_CustomImageVmFromAnUnmanagedGeneralizedOsImage.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createACustomImageVMFromAnUnmanagedGeneralizedOSImage() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "{vm-name}", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
StorageProfile: &armcompute.StorageProfile{
OSDisk: &armcompute.OSDisk{
Name: to.Ptr("myVMosdisk"),
Image: &armcompute.VirtualHardDisk{
URI: to.Ptr("http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/{existing-generalized-os-image-blob-name}.vhd"),
},
OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
Vhd: &armcompute.VirtualHardDisk{
URI: to.Ptr("http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk.vhd"),
},
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Image: &armcompute.VirtualHardDisk{
// URI: to.Ptr("https://{existing-storage-account-name}.blob.core.windows.net/system/Microsoft.Compute/Images/vhds/{existing-generalized-os-image-blob-name}.vhd"),
// },
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Vhd: &armcompute.VirtualHardDisk{
// URI: to.Ptr("http://{existing-storage-account-name}.blob.core.windows.net/vhds/myDisk.vhd"),
// },
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// VMID: to.Ptr("926cd555-a07c-4ff5-b214-4aa4dd09d79b"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Name: to.Ptr("myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_CustomImageVmFromAnUnmanagedGeneralizedOsImage.json
*/
async function createACustomImageVmFromAnUnmanagedGeneralizedOsImage() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "{vm-name}", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D1_v2" },
storageProfile: {
osDisk: {
name: "myVMosdisk",
image: {
uri: "http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/{existing-generalized-os-image-blob-name}.vhd",
},
osType: "Windows",
createOption: "FromImage",
caching: "ReadWrite",
vhd: {
uri: "http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk.vhd",
},
},
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"osDisk": {
"name": "myVMosdisk",
"image": {
"uri": "https://{existing-storage-account-name}.blob.core.windows.net/system/Microsoft.Compute/Images/vhds/{existing-generalized-os-image-blob-name}.vhd"
},
"caching": "ReadWrite",
"createOption": "FromImage",
"osType": "Windows",
"vhd": {
"uri": "http://{existing-storage-account-name}.blob.core.windows.net/vhds/myDisk.vhd"
}
},
"dataDisks": []
},
"vmId": "926cd555-a07c-4ff5-b214-4aa4dd09d79b",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"osDisk": {
"name": "myVMosdisk",
"image": {
"uri": "https://{existing-storage-account-name}.blob.core.windows.net/system/Microsoft.Compute/Images/vhds/{existing-generalized-os-image-blob-name}.vhd"
},
"caching": "ReadWrite",
"createOption": "FromImage",
"osType": "Windows",
"vhd": {
"uri": "http://{existing-storage-account-name}.blob.core.windows.net/vhds/myDisk.vhd"
}
},
"dataDisks": []
},
"vmId": "926cd555-a07c-4ff5-b214-4aa4dd09d79b",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a Linux vm with a patch setting assessmentMode of ImageDefault.
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"storageProfile": {
"imageReference": {
"sku": "16.04-LTS",
"publisher": "Canonical",
"version": "latest",
"offer": "UbuntuServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Premium_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}",
"linuxConfiguration": {
"provisionVMAgent": true,
"patchSettings": {
"assessmentMode": "ImageDefault"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.LinuxConfiguration;
import com.azure.resourcemanager.compute.models.LinuxPatchAssessmentMode;
import com.azure.resourcemanager.compute.models.LinuxPatchSettings;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* 2026-04-01/virtualMachineExamples/VirtualMachine_Create_LinuxVmWithPatchSettingAssessmentModeOfImageDefault.json
*/
/**
* Sample code: Create a Linux vm with a patch setting assessmentMode of ImageDefault.
*
* @param manager Entry point to ComputeManager.
*/
public static void createALinuxVmWithAPatchSettingAssessmentModeOfImageDefault(
com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM", new VirtualMachineInner()
.withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("Canonical").withOffer("UbuntuServer")
.withSku("16.04-LTS").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withLinuxConfiguration(new LinuxConfiguration().withProvisionVMAgent(true).withPatchSettings(
new LinuxPatchSettings().withAssessmentMode(LinuxPatchAssessmentMode.IMAGE_DEFAULT))))
.withNetworkProfile(new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_linux_vm_with_patch_setting_assessment_mode_of_image_default.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D2s_v3"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
"linuxConfiguration": {
"patchSettings": {"assessmentMode": "ImageDefault"},
"provisionVMAgent": True,
},
},
"storageProfile": {
"imageReference": {
"offer": "UbuntuServer",
"publisher": "Canonical",
"sku": "16.04-LTS",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Premium_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_LinuxVmWithPatchSettingAssessmentModeOfImageDefault.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_LinuxVmWithPatchSettingAssessmentModeOfImageDefault.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createALinuxVMWithAPatchSettingAssessmentModeOfImageDefault() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2SV3),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("16.04-LTS"),
Publisher: to.Ptr("Canonical"),
Version: to.Ptr("latest"),
Offer: to.Ptr("UbuntuServer"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
},
Name: to.Ptr("myVMosdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
LinuxConfiguration: &armcompute.LinuxConfiguration{
ProvisionVMAgent: to.Ptr(true),
PatchSettings: &armcompute.LinuxPatchSettings{
AssessmentMode: to.Ptr(armcompute.LinuxPatchAssessmentModeImageDefault),
},
},
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// LinuxConfiguration: &armcompute.LinuxConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// PatchSettings: &armcompute.LinuxPatchSettings{
// AssessmentMode: to.Ptr(armcompute.LinuxPatchAssessmentModeImageDefault),
// },
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("16.04-LTS"),
// Publisher: to.Ptr("Canonical"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("UbuntuServer"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
// },
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// VMID: to.Ptr("a149cd25-409f-41af-8088-275f5486bc93"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2SV3),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Name: to.Ptr("myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_LinuxVmWithPatchSettingAssessmentModeOfImageDefault.json
*/
async function createALinuxVmWithAPatchSettingAssessmentModeOfImageDefault() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D2s_v3" },
storageProfile: {
imageReference: {
sku: "16.04-LTS",
publisher: "Canonical",
version: "latest",
offer: "UbuntuServer",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Premium_LRS" },
name: "myVMosdisk",
createOption: "FromImage",
},
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
linuxConfiguration: {
provisionVMAgent: true,
patchSettings: { assessmentMode: "ImageDefault" },
},
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"provisionVMAgent": true,
"patchSettings": {
"assessmentMode": "ImageDefault"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "16.04-LTS",
"publisher": "Canonical",
"version": "latest",
"offer": "UbuntuServer"
},
"osDisk": {
"osType": "Linux",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"provisionVMAgent": true,
"patchSettings": {
"assessmentMode": "ImageDefault"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "16.04-LTS",
"publisher": "Canonical",
"version": "latest",
"offer": "UbuntuServer"
},
"osDisk": {
"osType": "Linux",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"storageProfile": {
"imageReference": {
"sku": "16.04-LTS",
"publisher": "Canonical",
"version": "latest",
"offer": "UbuntuServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Premium_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}",
"linuxConfiguration": {
"provisionVMAgent": true,
"patchSettings": {
"patchMode": "AutomaticByPlatform",
"assessmentMode": "AutomaticByPlatform",
"automaticByPlatformSettings": {
"rebootSetting": "Never",
"bypassPlatformSafetyChecksOnUserSchedule": true
}
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.LinuxConfiguration;
import com.azure.resourcemanager.compute.models.LinuxPatchAssessmentMode;
import com.azure.resourcemanager.compute.models.LinuxPatchSettings;
import com.azure.resourcemanager.compute.models.LinuxVMGuestPatchAutomaticByPlatformRebootSetting;
import com.azure.resourcemanager.compute.models.LinuxVMGuestPatchAutomaticByPlatformSettings;
import com.azure.resourcemanager.compute.models.LinuxVMGuestPatchMode;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* 2026-04-01/virtualMachineExamples/VirtualMachine_Create_LinuxVmWithAutomaticByPlatformSettings.json
*/
/**
* Sample code: Create a Linux vm with a patch setting patchMode of AutomaticByPlatform and
* AutomaticByPlatformSettings.
*
* @param manager Entry point to ComputeManager.
*/
public static void createALinuxVmWithAPatchSettingPatchModeOfAutomaticByPlatformAndAutomaticByPlatformSettings(
com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("Canonical").withOffer("UbuntuServer")
.withSku("16.04-LTS").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withLinuxConfiguration(new LinuxConfiguration().withProvisionVMAgent(true).withPatchSettings(
new LinuxPatchSettings().withPatchMode(LinuxVMGuestPatchMode.AUTOMATIC_BY_PLATFORM)
.withAssessmentMode(LinuxPatchAssessmentMode.AUTOMATIC_BY_PLATFORM)
.withAutomaticByPlatformSettings(new LinuxVMGuestPatchAutomaticByPlatformSettings()
.withRebootSetting(LinuxVMGuestPatchAutomaticByPlatformRebootSetting.NEVER)
.withBypassPlatformSafetyChecksOnUserSchedule(true)))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_linux_vm_with_automatic_by_platform_settings.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D2s_v3"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
"linuxConfiguration": {
"patchSettings": {
"assessmentMode": "AutomaticByPlatform",
"automaticByPlatformSettings": {
"bypassPlatformSafetyChecksOnUserSchedule": True,
"rebootSetting": "Never",
},
"patchMode": "AutomaticByPlatform",
},
"provisionVMAgent": True,
},
},
"storageProfile": {
"imageReference": {
"offer": "UbuntuServer",
"publisher": "Canonical",
"sku": "16.04-LTS",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Premium_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_LinuxVmWithAutomaticByPlatformSettings.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_LinuxVmWithAutomaticByPlatformSettings.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createALinuxVMWithAPatchSettingPatchModeOfAutomaticByPlatformAndAutomaticByPlatformSettings() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2SV3),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("16.04-LTS"),
Publisher: to.Ptr("Canonical"),
Version: to.Ptr("latest"),
Offer: to.Ptr("UbuntuServer"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
},
Name: to.Ptr("myVMosdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
LinuxConfiguration: &armcompute.LinuxConfiguration{
ProvisionVMAgent: to.Ptr(true),
PatchSettings: &armcompute.LinuxPatchSettings{
PatchMode: to.Ptr(armcompute.LinuxVMGuestPatchModeAutomaticByPlatform),
AssessmentMode: to.Ptr(armcompute.LinuxPatchAssessmentModeAutomaticByPlatform),
AutomaticByPlatformSettings: &armcompute.LinuxVMGuestPatchAutomaticByPlatformSettings{
RebootSetting: to.Ptr(armcompute.LinuxVMGuestPatchAutomaticByPlatformRebootSettingNever),
BypassPlatformSafetyChecksOnUserSchedule: to.Ptr(true),
},
},
},
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// LinuxConfiguration: &armcompute.LinuxConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// PatchSettings: &armcompute.LinuxPatchSettings{
// PatchMode: to.Ptr(armcompute.LinuxVMGuestPatchModeAutomaticByPlatform),
// AssessmentMode: to.Ptr(armcompute.LinuxPatchAssessmentModeAutomaticByPlatform),
// AutomaticByPlatformSettings: &armcompute.LinuxVMGuestPatchAutomaticByPlatformSettings{
// RebootSetting: to.Ptr(armcompute.LinuxVMGuestPatchAutomaticByPlatformRebootSettingNever),
// BypassPlatformSafetyChecksOnUserSchedule: to.Ptr(true),
// },
// },
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("16.04-LTS"),
// Publisher: to.Ptr("Canonical"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("UbuntuServer"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
// },
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// VMID: to.Ptr("a149cd25-409f-41af-8088-275f5486bc93"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2SV3),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Name: to.Ptr("myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_LinuxVmWithAutomaticByPlatformSettings.json
*/
async function createALinuxVmWithAPatchSettingPatchModeOfAutomaticByPlatformAndAutomaticByPlatformSettings() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D2s_v3" },
storageProfile: {
imageReference: {
sku: "16.04-LTS",
publisher: "Canonical",
version: "latest",
offer: "UbuntuServer",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Premium_LRS" },
name: "myVMosdisk",
createOption: "FromImage",
},
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
linuxConfiguration: {
provisionVMAgent: true,
patchSettings: {
patchMode: "AutomaticByPlatform",
assessmentMode: "AutomaticByPlatform",
automaticByPlatformSettings: {
rebootSetting: "Never",
bypassPlatformSafetyChecksOnUserSchedule: true,
},
},
},
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"provisionVMAgent": true,
"patchSettings": {
"patchMode": "AutomaticByPlatform",
"assessmentMode": "AutomaticByPlatform",
"automaticByPlatformSettings": {
"rebootSetting": "Never",
"bypassPlatformSafetyChecksOnUserSchedule": true
}
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "16.04-LTS",
"publisher": "Canonical",
"version": "latest",
"offer": "UbuntuServer"
},
"osDisk": {
"osType": "Linux",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"provisionVMAgent": true,
"patchSettings": {
"patchMode": "AutomaticByPlatform",
"assessmentMode": "AutomaticByPlatform",
"automaticByPlatformSettings": {
"rebootSetting": "Never",
"bypassPlatformSafetyChecksOnUserSchedule": true
}
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "16.04-LTS",
"publisher": "Canonical",
"version": "latest",
"offer": "UbuntuServer"
},
"osDisk": {
"osType": "Linux",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a Linux vm with a patch setting patchMode of ImageDefault.
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"storageProfile": {
"imageReference": {
"sku": "16.04-LTS",
"publisher": "Canonical",
"version": "latest",
"offer": "UbuntuServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Premium_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}",
"linuxConfiguration": {
"provisionVMAgent": true,
"patchSettings": {
"patchMode": "ImageDefault"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.LinuxConfiguration;
import com.azure.resourcemanager.compute.models.LinuxPatchSettings;
import com.azure.resourcemanager.compute.models.LinuxVMGuestPatchMode;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* 2026-04-01/virtualMachineExamples/VirtualMachine_Create_LinuxVmWithPatchSettingModeOfImageDefault.json
*/
/**
* Sample code: Create a Linux vm with a patch setting patchMode of ImageDefault.
*
* @param manager Entry point to ComputeManager.
*/
public static void createALinuxVmWithAPatchSettingPatchModeOfImageDefault(
com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM", new VirtualMachineInner()
.withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("Canonical").withOffer("UbuntuServer")
.withSku("16.04-LTS").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withLinuxConfiguration(new LinuxConfiguration().withProvisionVMAgent(true)
.withPatchSettings(new LinuxPatchSettings().withPatchMode(LinuxVMGuestPatchMode.IMAGE_DEFAULT))))
.withNetworkProfile(new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_linux_vm_with_patch_setting_mode_of_image_default.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D2s_v3"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
"linuxConfiguration": {"patchSettings": {"patchMode": "ImageDefault"}, "provisionVMAgent": True},
},
"storageProfile": {
"imageReference": {
"offer": "UbuntuServer",
"publisher": "Canonical",
"sku": "16.04-LTS",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Premium_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_LinuxVmWithPatchSettingModeOfImageDefault.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_LinuxVmWithPatchSettingModeOfImageDefault.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createALinuxVMWithAPatchSettingPatchModeOfImageDefault() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2SV3),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("16.04-LTS"),
Publisher: to.Ptr("Canonical"),
Version: to.Ptr("latest"),
Offer: to.Ptr("UbuntuServer"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
},
Name: to.Ptr("myVMosdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
LinuxConfiguration: &armcompute.LinuxConfiguration{
ProvisionVMAgent: to.Ptr(true),
PatchSettings: &armcompute.LinuxPatchSettings{
PatchMode: to.Ptr(armcompute.LinuxVMGuestPatchModeImageDefault),
},
},
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// LinuxConfiguration: &armcompute.LinuxConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// PatchSettings: &armcompute.LinuxPatchSettings{
// PatchMode: to.Ptr(armcompute.LinuxVMGuestPatchModeImageDefault),
// },
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("16.04-LTS"),
// Publisher: to.Ptr("Canonical"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("UbuntuServer"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
// },
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// VMID: to.Ptr("a149cd25-409f-41af-8088-275f5486bc93"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2SV3),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Name: to.Ptr("myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_LinuxVmWithPatchSettingModeOfImageDefault.json
*/
async function createALinuxVmWithAPatchSettingPatchModeOfImageDefault() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D2s_v3" },
storageProfile: {
imageReference: {
sku: "16.04-LTS",
publisher: "Canonical",
version: "latest",
offer: "UbuntuServer",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Premium_LRS" },
name: "myVMosdisk",
createOption: "FromImage",
},
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
linuxConfiguration: { provisionVMAgent: true, patchSettings: { patchMode: "ImageDefault" } },
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"provisionVMAgent": true,
"patchSettings": {
"patchMode": "ImageDefault"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "16.04-LTS",
"publisher": "Canonical",
"version": "latest",
"offer": "UbuntuServer"
},
"osDisk": {
"osType": "Linux",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"provisionVMAgent": true,
"patchSettings": {
"patchMode": "ImageDefault"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "16.04-LTS",
"publisher": "Canonical",
"version": "latest",
"offer": "UbuntuServer"
},
"osDisk": {
"osType": "Linux",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"storageProfile": {
"imageReference": {
"sku": "16.04-LTS",
"publisher": "Canonical",
"version": "latest",
"offer": "UbuntuServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Premium_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}",
"linuxConfiguration": {
"provisionVMAgent": true,
"patchSettings": {
"patchMode": "AutomaticByPlatform",
"assessmentMode": "AutomaticByPlatform"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.LinuxConfiguration;
import com.azure.resourcemanager.compute.models.LinuxPatchAssessmentMode;
import com.azure.resourcemanager.compute.models.LinuxPatchSettings;
import com.azure.resourcemanager.compute.models.LinuxVMGuestPatchMode;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* 2026-04-01/virtualMachineExamples/VirtualMachine_Create_LinuxVmWithPatchSettingModesOfAutomaticByPlatform.json
*/
/**
* Sample code: Create a Linux vm with a patch settings patchMode and assessmentMode set to AutomaticByPlatform.
*
* @param manager Entry point to ComputeManager.
*/
public static void createALinuxVmWithAPatchSettingsPatchModeAndAssessmentModeSetToAutomaticByPlatform(
com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("Canonical").withOffer("UbuntuServer")
.withSku("16.04-LTS").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withLinuxConfiguration(new LinuxConfiguration().withProvisionVMAgent(true).withPatchSettings(
new LinuxPatchSettings().withPatchMode(LinuxVMGuestPatchMode.AUTOMATIC_BY_PLATFORM)
.withAssessmentMode(LinuxPatchAssessmentMode.AUTOMATIC_BY_PLATFORM))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_linux_vm_with_patch_setting_modes_of_automatic_by_platform.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D2s_v3"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
"linuxConfiguration": {
"patchSettings": {"assessmentMode": "AutomaticByPlatform", "patchMode": "AutomaticByPlatform"},
"provisionVMAgent": True,
},
},
"storageProfile": {
"imageReference": {
"offer": "UbuntuServer",
"publisher": "Canonical",
"sku": "16.04-LTS",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Premium_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_LinuxVmWithPatchSettingModesOfAutomaticByPlatform.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_LinuxVmWithPatchSettingModesOfAutomaticByPlatform.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createALinuxVMWithAPatchSettingsPatchModeAndAssessmentModeSetToAutomaticByPlatform() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2SV3),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("16.04-LTS"),
Publisher: to.Ptr("Canonical"),
Version: to.Ptr("latest"),
Offer: to.Ptr("UbuntuServer"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
},
Name: to.Ptr("myVMosdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
LinuxConfiguration: &armcompute.LinuxConfiguration{
ProvisionVMAgent: to.Ptr(true),
PatchSettings: &armcompute.LinuxPatchSettings{
PatchMode: to.Ptr(armcompute.LinuxVMGuestPatchModeAutomaticByPlatform),
AssessmentMode: to.Ptr(armcompute.LinuxPatchAssessmentModeAutomaticByPlatform),
},
},
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// LinuxConfiguration: &armcompute.LinuxConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// PatchSettings: &armcompute.LinuxPatchSettings{
// PatchMode: to.Ptr(armcompute.LinuxVMGuestPatchModeAutomaticByPlatform),
// AssessmentMode: to.Ptr(armcompute.LinuxPatchAssessmentModeAutomaticByPlatform),
// },
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("16.04-LTS"),
// Publisher: to.Ptr("Canonical"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("UbuntuServer"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
// },
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// VMID: to.Ptr("a149cd25-409f-41af-8088-275f5486bc93"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2SV3),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Name: to.Ptr("myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_LinuxVmWithPatchSettingModesOfAutomaticByPlatform.json
*/
async function createALinuxVmWithAPatchSettingsPatchModeAndAssessmentModeSetToAutomaticByPlatform() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D2s_v3" },
storageProfile: {
imageReference: {
sku: "16.04-LTS",
publisher: "Canonical",
version: "latest",
offer: "UbuntuServer",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Premium_LRS" },
name: "myVMosdisk",
createOption: "FromImage",
},
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
linuxConfiguration: {
provisionVMAgent: true,
patchSettings: { patchMode: "AutomaticByPlatform", assessmentMode: "AutomaticByPlatform" },
},
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"provisionVMAgent": true,
"patchSettings": {
"patchMode": "AutomaticByPlatform",
"assessmentMode": "AutomaticByPlatform"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "16.04-LTS",
"publisher": "Canonical",
"version": "latest",
"offer": "UbuntuServer"
},
"osDisk": {
"osType": "Linux",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"provisionVMAgent": true,
"patchSettings": {
"patchMode": "AutomaticByPlatform",
"assessmentMode": "AutomaticByPlatform"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "16.04-LTS",
"publisher": "Canonical",
"version": "latest",
"offer": "UbuntuServer"
},
"osDisk": {
"osType": "Linux",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/{vm-name}?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D2_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"vhd": {
"uri": "http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk.vhd"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": [
{
"diskSizeGB": 1023,
"createOption": "Empty",
"lun": 0,
"vhd": {
"uri": "http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk0.vhd"
}
},
{
"diskSizeGB": 1023,
"createOption": "Empty",
"lun": 1,
"vhd": {
"uri": "http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk1.vhd"
}
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DataDisk;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualHardDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* 2026-04-01/virtualMachineExamples/VirtualMachine_Create_PlatformImageVmWithUnmanagedOsAndDataDisks.json
*/
/**
* Sample code: Create a platform-image vm with unmanaged os and data disks.
*
* @param manager Entry point to ComputeManager.
*/
public static void
createAPlatformImageVmWithUnmanagedOsAndDataDisks(com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "{vm-name}",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withVhd(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk.vhd"))
.withCaching(CachingTypes.READ_WRITE).withCreateOption(DiskCreateOptionTypes.FROM_IMAGE))
.withDataDisks(Arrays.asList(new DataDisk().withLun(0).withVhd(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk0.vhd"))
.withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023),
new DataDisk().withLun(1).withVhd(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk1.vhd"))
.withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_platform_image_vm_with_unmanaged_os_and_data_disks.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="{vm-name}",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D2_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"dataDisks": [
{
"createOption": "Empty",
"diskSizeGB": 1023,
"lun": 0,
"vhd": {
"uri": "http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk0.vhd"
},
},
{
"createOption": "Empty",
"diskSizeGB": 1023,
"lun": 1,
"vhd": {
"uri": "http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk1.vhd"
},
},
],
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"vhd": {
"uri": "http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk.vhd"
},
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_PlatformImageVmWithUnmanagedOsAndDataDisks.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_PlatformImageVmWithUnmanagedOsAndDataDisks.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAPlatformImageVMWithUnmanagedOSAndDataDisks() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "{vm-name}", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2V2),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("2016-Datacenter"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
Version: to.Ptr("latest"),
Offer: to.Ptr("WindowsServer"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
Vhd: &armcompute.VirtualHardDisk{
URI: to.Ptr("http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk.vhd"),
},
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
Name: to.Ptr("myVMosdisk"),
},
DataDisks: []*armcompute.DataDisk{
{
DiskSizeGB: to.Ptr[int32](1023),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesEmpty),
Lun: to.Ptr[int32](0),
Vhd: &armcompute.VirtualHardDisk{
URI: to.Ptr("http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk0.vhd"),
},
},
{
DiskSizeGB: to.Ptr[int32](1023),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesEmpty),
Lun: to.Ptr[int32](1),
Vhd: &armcompute.VirtualHardDisk{
URI: to.Ptr("http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk1.vhd"),
},
},
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("2016-Datacenter"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("WindowsServer"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Vhd: &armcompute.VirtualHardDisk{
// URI: to.Ptr("http://{existing-storage-account-name}.blob.core.windows.net/vhds/myDisk.vhd"),
// },
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// },
// DataDisks: []*armcompute.DataDisk{
// {
// Name: to.Ptr("dataDisk0"),
// DiskSizeGB: to.Ptr[int32](1023),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesEmpty),
// Caching: to.Ptr(armcompute.CachingTypesNone),
// Vhd: &armcompute.VirtualHardDisk{
// URI: to.Ptr("http://{existing-storage-account-name}.blob.core.windows.net/vhds/myDisk0.vhd"),
// },
// Lun: to.Ptr[int32](0),
// },
// {
// Name: to.Ptr("dataDisk1"),
// DiskSizeGB: to.Ptr[int32](1023),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesEmpty),
// Caching: to.Ptr(armcompute.CachingTypesNone),
// Vhd: &armcompute.VirtualHardDisk{
// URI: to.Ptr("http://{existing-storage-account-name}.blob.core.windows.net/vhds/myDisk1.vhd"),
// },
// Lun: to.Ptr[int32](1),
// },
// },
// },
// VMID: to.Ptr("5230a749-2f68-4830-900b-702182d32e63"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2V2),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Name: to.Ptr("myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_PlatformImageVmWithUnmanagedOsAndDataDisks.json
*/
async function createAPlatformImageVmWithUnmanagedOsAndDataDisks() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "{vm-name}", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D2_v2" },
storageProfile: {
imageReference: {
sku: "2016-Datacenter",
publisher: "MicrosoftWindowsServer",
version: "latest",
offer: "WindowsServer",
},
osDisk: {
caching: "ReadWrite",
vhd: {
uri: "http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk.vhd",
},
createOption: "FromImage",
name: "myVMosdisk",
},
dataDisks: [
{
diskSizeGB: 1023,
createOption: "Empty",
lun: 0,
vhd: {
uri: "http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk0.vhd",
},
},
{
diskSizeGB: 1023,
createOption: "Empty",
lun: 1,
vhd: {
uri: "http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk1.vhd",
},
},
],
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"vhd": {
"uri": "http://{existing-storage-account-name}.blob.core.windows.net/vhds/myDisk.vhd"
},
"createOption": "FromImage",
"name": "myVMosdisk",
"caching": "ReadWrite"
},
"dataDisks": [
{
"name": "dataDisk0",
"diskSizeGB": 1023,
"createOption": "Empty",
"caching": "None",
"vhd": {
"uri": "http://{existing-storage-account-name}.blob.core.windows.net/vhds/myDisk0.vhd"
},
"lun": 0
},
{
"name": "dataDisk1",
"diskSizeGB": 1023,
"createOption": "Empty",
"caching": "None",
"vhd": {
"uri": "http://{existing-storage-account-name}.blob.core.windows.net/vhds/myDisk1.vhd"
},
"lun": 1
}
]
},
"vmId": "5230a749-2f68-4830-900b-702182d32e63",
"hardwareProfile": {
"vmSize": "Standard_D2_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"vhd": {
"uri": "http://{existing-storage-account-name}.blob.core.windows.net/vhds/myDisk.vhd"
},
"createOption": "FromImage",
"name": "myVMosdisk",
"caching": "ReadWrite"
},
"dataDisks": [
{
"name": "dataDisk0",
"diskSizeGB": 1023,
"createOption": "Empty",
"caching": "None",
"vhd": {
"uri": "http://{existing-storage-account-name}.blob.core.windows.net/vhds/myDisk0.vhd"
},
"lun": 0
},
{
"name": "dataDisk1",
"diskSizeGB": 1023,
"createOption": "Empty",
"caching": "None",
"vhd": {
"uri": "http://{existing-storage-account-name}.blob.core.windows.net/vhds/myDisk1.vhd"
},
"lun": 1
}
]
},
"vmId": "5230a749-2f68-4830-900b-702182d32e63",
"hardwareProfile": {
"vmSize": "Standard_D2_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"communityGalleryImageId": "/CommunityGalleries/galleryPublicName/Images/communityGalleryImageName/Versions/communityGalleryImageVersionName"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_FromACommunityGalleryImage.json
*/
/**
* Sample code: Create a VM from a community gallery image.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAVMFromACommunityGalleryImage(com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM", new VirtualMachineInner()
.withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withCommunityGalleryImageId(
"/CommunityGalleries/galleryPublicName/Images/communityGalleryImageName/Versions/communityGalleryImageVersionName"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_from_acommunity_gallery_image.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"communityGalleryImageId": "/CommunityGalleries/galleryPublicName/Images/communityGalleryImageName/Versions/communityGalleryImageVersionName"
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_FromACommunityGalleryImage.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_FromACommunityGalleryImage.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMFromACommunityGalleryImage() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
CommunityGalleryImageID: to.Ptr("/CommunityGalleries/galleryPublicName/Images/communityGalleryImageName/Versions/communityGalleryImageVersionName"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
Name: to.Ptr("myVMosdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// LinuxConfiguration: &armcompute.LinuxConfiguration{
// DisablePasswordAuthentication: to.Ptr(false),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// CommunityGalleryImageID: to.Ptr("/CommunityGalleries/galleryPublicName/Images/communityGalleryImageName/Versions/communityGalleryImageVersionName"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// DiskSizeGB: to.Ptr[int32](30),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// VMID: to.Ptr("71aa3d5a-d73d-4970-9182-8580433b2865"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Name: to.Ptr("myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_FromACommunityGalleryImage.json
*/
async function createAVMFromACommunityGalleryImage() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D1_v2" },
storageProfile: {
imageReference: {
communityGalleryImageId:
"/CommunityGalleries/galleryPublicName/Images/communityGalleryImageName/Versions/communityGalleryImageVersionName",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Standard_LRS" },
name: "myVMosdisk",
createOption: "FromImage",
},
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"disablePasswordAuthentication": false
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"communityGalleryImageId": "/CommunityGalleries/galleryPublicName/Images/communityGalleryImageName/Versions/communityGalleryImageVersionName"
},
"osDisk": {
"name": "myVMosdisk",
"diskSizeGB": 30,
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"caching": "ReadWrite",
"createOption": "FromImage",
"osType": "Linux"
},
"dataDisks": []
},
"vmId": "71aa3d5a-d73d-4970-9182-8580433b2865",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"disablePasswordAuthentication": false
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"communityGalleryImageId": "/CommunityGalleries/galleryPublicName/Images/communityGalleryImageName/Versions/communityGalleryImageVersionName"
},
"osDisk": {
"name": "myVMosdisk",
"diskSizeGB": 30,
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"caching": "ReadWrite",
"createOption": "FromImage",
"osType": "Linux"
},
"dataDisks": []
},
"vmId": "71aa3d5a-d73d-4970-9182-8580433b2865",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a vm from a custom image.
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_FromACustomImage.json
*/
/**
* Sample code: Create a vm from a custom image.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAVmFromACustomImage(com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM", new VirtualMachineInner()
.withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withImageReference(new ImageReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_from_acustom_image.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}"
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_FromACustomImage.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_FromACustomImage.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMFromACustomImage() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
Name: to.Ptr("myVMosdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// LinuxConfiguration: &armcompute.LinuxConfiguration{
// DisablePasswordAuthentication: to.Ptr(false),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/nsgcustom"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// DiskSizeGB: to.Ptr[int32](30),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// VMID: to.Ptr("71aa3d5a-d73d-4970-9182-8580433b2865"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Name: to.Ptr("myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_FromACustomImage.json
*/
async function createAVmFromACustomImage() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D1_v2" },
storageProfile: {
imageReference: {
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Standard_LRS" },
name: "myVMosdisk",
createOption: "FromImage",
},
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"disablePasswordAuthentication": false
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/nsgcustom"
},
"osDisk": {
"name": "myVMosdisk",
"diskSizeGB": 30,
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"caching": "ReadWrite",
"createOption": "FromImage",
"osType": "Linux"
},
"dataDisks": []
},
"vmId": "71aa3d5a-d73d-4970-9182-8580433b2865",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"disablePasswordAuthentication": false
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/nsgcustom"
},
"osDisk": {
"name": "myVMosdisk",
"diskSizeGB": 30,
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"caching": "ReadWrite",
"createOption": "FromImage",
"osType": "Linux"
},
"dataDisks": []
},
"vmId": "71aa3d5a-d73d-4970-9182-8580433b2865",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a vm from a generalized shared image.
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_FromAGeneralizedSharedImage.json
*/
/**
* Sample code: Create a vm from a generalized shared image.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAVmFromAGeneralizedSharedImage(com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM", new VirtualMachineInner()
.withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withImageReference(new ImageReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_from_ageneralized_shared_image.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_FromAGeneralizedSharedImage.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_FromAGeneralizedSharedImage.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMFromAGeneralizedSharedImage() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
Name: to.Ptr("myVMosdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// LinuxConfiguration: &armcompute.LinuxConfiguration{
// DisablePasswordAuthentication: to.Ptr(false),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// DiskSizeGB: to.Ptr[int32](30),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// VMID: to.Ptr("71aa3d5a-d73d-4970-9182-8580433b2865"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Name: to.Ptr("myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_FromAGeneralizedSharedImage.json
*/
async function createAVmFromAGeneralizedSharedImage() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D1_v2" },
storageProfile: {
imageReference: {
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Standard_LRS" },
name: "myVMosdisk",
createOption: "FromImage",
},
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"disablePasswordAuthentication": false
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"
},
"osDisk": {
"name": "myVMosdisk",
"diskSizeGB": 30,
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"caching": "ReadWrite",
"createOption": "FromImage",
"osType": "Linux"
},
"dataDisks": []
},
"vmId": "71aa3d5a-d73d-4970-9182-8580433b2865",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"disablePasswordAuthentication": false
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"
},
"osDisk": {
"name": "myVMosdisk",
"diskSizeGB": 30,
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"caching": "ReadWrite",
"createOption": "FromImage",
"osType": "Linux"
},
"dataDisks": []
},
"vmId": "71aa3d5a-d73d-4970-9182-8580433b2865",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a VM from a shared gallery image
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sharedGalleryImageId": "/SharedGalleries/sharedGalleryName/Images/sharedGalleryImageName/Versions/sharedGalleryImageVersionName"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_FromASharedGalleryImage.json
*/
/**
* Sample code: Create a VM from a shared gallery image.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAVMFromASharedGalleryImage(com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM", new VirtualMachineInner()
.withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withImageReference(new ImageReference().withSharedGalleryImageId(
"/SharedGalleries/sharedGalleryName/Images/sharedGalleryImageName/Versions/sharedGalleryImageVersionName"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_from_ashared_gallery_image.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"sharedGalleryImageId": "/SharedGalleries/sharedGalleryName/Images/sharedGalleryImageName/Versions/sharedGalleryImageVersionName"
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_FromASharedGalleryImage.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_FromASharedGalleryImage.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMFromASharedGalleryImage() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SharedGalleryImageID: to.Ptr("/SharedGalleries/sharedGalleryName/Images/sharedGalleryImageName/Versions/sharedGalleryImageVersionName"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
Name: to.Ptr("myVMosdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// LinuxConfiguration: &armcompute.LinuxConfiguration{
// DisablePasswordAuthentication: to.Ptr(false),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SharedGalleryImageID: to.Ptr("/SharedGalleries/sharedGalleryName/Images/sharedGalleryImageName/Versions/sharedGalleryImageVersionName"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// DiskSizeGB: to.Ptr[int32](30),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// VMID: to.Ptr("71aa3d5a-d73d-4970-9182-8580433b2865"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Name: to.Ptr("myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_FromASharedGalleryImage.json
*/
async function createAVMFromASharedGalleryImage() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D1_v2" },
storageProfile: {
imageReference: {
sharedGalleryImageId:
"/SharedGalleries/sharedGalleryName/Images/sharedGalleryImageName/Versions/sharedGalleryImageVersionName",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Standard_LRS" },
name: "myVMosdisk",
createOption: "FromImage",
},
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"disablePasswordAuthentication": false
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sharedGalleryImageId": "/SharedGalleries/sharedGalleryName/Images/sharedGalleryImageName/Versions/sharedGalleryImageVersionName"
},
"osDisk": {
"name": "myVMosdisk",
"diskSizeGB": 30,
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"caching": "ReadWrite",
"createOption": "FromImage",
"osType": "Linux"
},
"dataDisks": []
},
"vmId": "71aa3d5a-d73d-4970-9182-8580433b2865",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"disablePasswordAuthentication": false
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sharedGalleryImageId": "/SharedGalleries/sharedGalleryName/Images/sharedGalleryImageName/Versions/sharedGalleryImageVersionName"
},
"osDisk": {
"name": "myVMosdisk",
"diskSizeGB": 30,
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"caching": "ReadWrite",
"createOption": "FromImage",
"osType": "Linux"
},
"dataDisks": []
},
"vmId": "71aa3d5a-d73d-4970-9182-8580433b2865",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a vm from a specialized shared image.
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_FromASpecializedSharedImage.json
*/
/**
* Sample code: Create a vm from a specialized shared image.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAVmFromASpecializedSharedImage(com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM", new VirtualMachineInner()
.withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withImageReference(new ImageReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withNetworkProfile(new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_from_aspecialized_shared_image.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"storageProfile": {
"imageReference": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_FromASpecializedSharedImage.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_FromASpecializedSharedImage.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMFromASpecializedSharedImage() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
Name: to.Ptr("myVMosdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// DiskSizeGB: to.Ptr[int32](30),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// VMID: to.Ptr("71aa3d5a-d73d-4970-9182-8580433b2865"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Name: to.Ptr("myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_FromASpecializedSharedImage.json
*/
async function createAVmFromASpecializedSharedImage() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D1_v2" },
storageProfile: {
imageReference: {
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Standard_LRS" },
name: "myVMosdisk",
createOption: "FromImage",
},
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"
},
"osDisk": {
"name": "myVMosdisk",
"diskSizeGB": 30,
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"caching": "ReadWrite",
"createOption": "FromImage",
"osType": "Linux"
},
"dataDisks": []
},
"vmId": "71aa3d5a-d73d-4970-9182-8580433b2865",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"
},
"osDisk": {
"name": "myVMosdisk",
"diskSizeGB": 30,
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"caching": "ReadWrite",
"createOption": "FromImage",
"osType": "Linux"
},
"dataDisks": []
},
"vmId": "71aa3d5a-d73d-4970-9182-8580433b2865",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a vm in a Virtual Machine Scale Set with customer assigned platformFaultDomain.
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"virtualMachineScaleSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{existing-flex-vmss-name-with-platformFaultDomainCount-greater-than-1}"
},
"platformFaultDomain": 1
}
}
import com.azure.core.management.SubResource;
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* 2026-04-01/virtualMachineExamples/VirtualMachine_Create_InAVmssWithCustomerAssignedPlatformFaultDomain.json
*/
/**
* Sample code: Create a vm in a Virtual Machine Scale Set with customer assigned platformFaultDomain.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAVmInAVirtualMachineScaleSetWithCustomerAssignedPlatformFaultDomain(
com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile()
.withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withVirtualMachineScaleSet(new SubResource().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{existing-flex-vmss-name-with-platformFaultDomainCount-greater-than-1}"))
.withPlatformFaultDomain(1),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_in_avmss_with_customer_assigned_platform_fault_domain.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"platformFaultDomain": 1,
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
"virtualMachineScaleSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{existing-flex-vmss-name-with-platformFaultDomainCount-greater-than-1}"
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_InAVmssWithCustomerAssignedPlatformFaultDomain.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_InAVmssWithCustomerAssignedPlatformFaultDomain.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMInAVirtualMachineScaleSetWithCustomerAssignedPlatformFaultDomain() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("2016-Datacenter"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
Version: to.Ptr("latest"),
Offer: to.Ptr("WindowsServer"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
Name: to.Ptr("myVMosdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
VirtualMachineScaleSet: &armcompute.SubResource{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{existing-flex-vmss-name-with-platformFaultDomainCount-greater-than-1}"),
},
PlatformFaultDomain: to.Ptr[int32](1),
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("2016-Datacenter"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("WindowsServer"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// VMID: to.Ptr("7cce54f2-ecd3-4ddd-a8d9-50984faa3918"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// VirtualMachineScaleSet: &armcompute.SubResource{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/myExistingFlexVmss"),
// },
// PlatformFaultDomain: to.Ptr[int32](1),
// ProvisioningState: to.Ptr("Creating"),
// },
// Name: to.Ptr("myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_InAVmssWithCustomerAssignedPlatformFaultDomain.json
*/
async function createAVmInAVirtualMachineScaleSetWithCustomerAssignedPlatformFaultDomain() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D1_v2" },
storageProfile: {
imageReference: {
sku: "2016-Datacenter",
publisher: "MicrosoftWindowsServer",
version: "latest",
offer: "WindowsServer",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Standard_LRS" },
name: "myVMosdisk",
createOption: "FromImage",
},
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
virtualMachineScaleSet: {
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{existing-flex-vmss-name-with-platformFaultDomainCount-greater-than-1}",
},
platformFaultDomain: 1,
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"vmId": "7cce54f2-ecd3-4ddd-a8d9-50984faa3918",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"virtualMachineScaleSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/myExistingFlexVmss"
},
"platformFaultDomain": 1,
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"vmId": "7cce54f2-ecd3-4ddd-a8d9-50984faa3918",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"virtualMachineScaleSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/myExistingFlexVmss"
},
"platformFaultDomain": 1,
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a vm in an availability set.
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"availabilitySet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/availabilitySets/{existing-availability-set-name}"
}
}
}
import com.azure.core.management.SubResource;
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_InAnAvailabilitySet.json
*/
/**
* Sample code: Create a vm in an availability set.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAVmInAnAvailabilitySet(com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile()
.withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withAvailabilitySet(new SubResource().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/availabilitySets/{existing-availability-set-name}")),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_in_an_availability_set.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"availabilitySet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/availabilitySets/{existing-availability-set-name}"
},
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_InAnAvailabilitySet.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_InAnAvailabilitySet.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMInAnAvailabilitySet() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("2016-Datacenter"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
Version: to.Ptr("latest"),
Offer: to.Ptr("WindowsServer"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
Name: to.Ptr("myVMosdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
AvailabilitySet: &armcompute.SubResource{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/availabilitySets/{existing-availability-set-name}"),
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("2016-Datacenter"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("WindowsServer"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// VMID: to.Ptr("b7a098cc-b0b8-46e8-a205-62f301a62a8f"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// AvailabilitySet: &armcompute.SubResource{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/availabilitySets/NSGEXISTINGAS"),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Name: to.Ptr("myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_InAnAvailabilitySet.json
*/
async function createAVmInAnAvailabilitySet() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D1_v2" },
storageProfile: {
imageReference: {
sku: "2016-Datacenter",
publisher: "MicrosoftWindowsServer",
version: "latest",
offer: "WindowsServer",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Standard_LRS" },
name: "myVMosdisk",
createOption: "FromImage",
},
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
availabilitySet: {
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/availabilitySets/{existing-availability-set-name}",
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"vmId": "b7a098cc-b0b8-46e8-a205-62f301a62a8f",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"availabilitySet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/availabilitySets/NSGEXISTINGAS"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"vmId": "b7a098cc-b0b8-46e8-a205-62f301a62a8f",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"availabilitySet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/availabilitySets/NSGEXISTINGAS"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a vm with a marketplace image plan.
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"plan": {
"publisher": "microsoft-ads",
"product": "windows-data-science-vm",
"name": "windows2016"
},
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "windows2016",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "windows-data-science-vm"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.Plan;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithAMarketplaceImagePlan.json
*/
/**
* Sample code: Create a vm with a marketplace image plan.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAVmWithAMarketplaceImagePlan(com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile()
.withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_with_amarketplace_image_plan.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"plan": {"name": "windows2016", "product": "windows-data-science-vm", "publisher": "microsoft-ads"},
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"offer": "windows-data-science-vm",
"publisher": "microsoft-ads",
"sku": "windows2016",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithAMarketplaceImagePlan.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithAMarketplaceImagePlan.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMWithAMarketplaceImagePlan() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Plan: &armcompute.Plan{
Publisher: to.Ptr("microsoft-ads"),
Product: to.Ptr("windows-data-science-vm"),
Name: to.Ptr("windows2016"),
},
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("windows2016"),
Publisher: to.Ptr("microsoft-ads"),
Version: to.Ptr("latest"),
Offer: to.Ptr("windows-data-science-vm"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
Name: to.Ptr("myVMosdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("standard-data-science-vm"),
// Publisher: to.Ptr("microsoft-ads"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("standard-data-science-vm"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// VMID: to.Ptr("5c0d55a7-c407-4ed6-bf7d-ddb810267c85"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Plan: &armcompute.Plan{
// Publisher: to.Ptr("microsoft-ads"),
// Product: to.Ptr("standard-data-science-vm"),
// Name: to.Ptr("standard-data-science-vm"),
// },
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithAMarketplaceImagePlan.json
*/
async function createAVmWithAMarketplaceImagePlan() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
plan: { publisher: "microsoft-ads", product: "windows-data-science-vm", name: "windows2016" },
hardwareProfile: { vmSize: "Standard_D1_v2" },
storageProfile: {
imageReference: {
sku: "windows2016",
publisher: "microsoft-ads",
version: "latest",
offer: "windows-data-science-vm",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Standard_LRS" },
name: "myVMosdisk",
createOption: "FromImage",
},
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "standard-data-science-vm",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "standard-data-science-vm"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"plan": {
"publisher": "microsoft-ads",
"product": "standard-data-science-vm",
"name": "standard-data-science-vm"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "standard-data-science-vm",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "standard-data-science-vm"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"plan": {
"publisher": "microsoft-ads",
"product": "standard-data-science-vm",
"name": "standard-data-science-vm"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
Create a vm with additional disk properties (network access policy and tier).
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D4s_v3"
},
"storageProfile": {
"imageReference": {
"sku": "2022-datacenter-azure-edition",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"diskApiVersion": "2026-03-02",
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Premium_LRS",
"additionalDiskProperties": {
"managedDiskProperties": {
"networkAccessPolicy": "AllowPrivate",
"diskAccessId": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskAccesses/myDiskAccess"
}
}
},
"name": "myVMosdisk",
"createOption": "FromImage"
},
"dataDisks": [
{
"lun": 0,
"name": "myDataDisk",
"createOption": "Empty",
"diskSizeGB": 1024,
"managedDisk": {
"storageAccountType": "Premium_LRS",
"additionalDiskProperties": {
"managedDiskProperties": {
"networkAccessPolicy": "AllowPrivate",
"diskAccessId": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskAccesses/myDiskAccess",
"tier": "P30"
}
}
}
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.AdditionalDiskProperties;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DataDisk;
import com.azure.resourcemanager.compute.models.DiskApiVersion;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineDiskNetworkAccessPolicy;
import com.azure.resourcemanager.compute.models.VirtualMachineDiskProperties;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithAdditionalDiskProperties.json
*/
/**
* Sample code: Create a vm with additional disk properties (network access policy and tier).
*
* @param manager Entry point to ComputeManager.
*/
public static void createAVmWithAdditionalDiskPropertiesNetworkAccessPolicyAndTier(
com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM", new VirtualMachineInner()
.withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D4S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2022-datacenter-azure-edition").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS)
.withAdditionalDiskProperties(
new AdditionalDiskProperties().withManagedDiskProperties(new VirtualMachineDiskProperties()
.withNetworkAccessPolicy(VirtualMachineDiskNetworkAccessPolicy.ALLOW_PRIVATE)
.withDiskAccessId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskAccesses/myDiskAccess")))))
.withDataDisks(Arrays.asList(new DataDisk().withLun(0).withName("myDataDisk")
.withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1024)
.withManagedDisk(new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS)
.withAdditionalDiskProperties(new AdditionalDiskProperties()
.withManagedDiskProperties(new VirtualMachineDiskProperties().withTier("P30")
.withNetworkAccessPolicy(VirtualMachineDiskNetworkAccessPolicy.ALLOW_PRIVATE)
.withDiskAccessId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskAccesses/myDiskAccess"))))))
.withDiskApiVersion(DiskApiVersion.TWO_ZERO_TWO_SIX_ZERO_THREE_ZERO_TWO))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_with_additional_disk_properties.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D4s_v3"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"dataDisks": [
{
"createOption": "Empty",
"diskSizeGB": 1024,
"lun": 0,
"managedDisk": {
"additionalDiskProperties": {
"managedDiskProperties": {
"diskAccessId": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskAccesses/myDiskAccess",
"networkAccessPolicy": "AllowPrivate",
"tier": "P30",
}
},
"storageAccountType": "Premium_LRS",
},
"name": "myDataDisk",
}
],
"diskApiVersion": "2026-03-02",
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2022-datacenter-azure-edition",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {
"additionalDiskProperties": {
"managedDiskProperties": {
"diskAccessId": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskAccesses/myDiskAccess",
"networkAccessPolicy": "AllowPrivate",
}
},
"storageAccountType": "Premium_LRS",
},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithAdditionalDiskProperties.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithAdditionalDiskProperties.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMWithAdditionalDiskPropertiesNetworkAccessPolicyAndTier() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD4SV3),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("2022-datacenter-azure-edition"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
Version: to.Ptr("latest"),
Offer: to.Ptr("WindowsServer"),
},
DiskAPIVersion: to.Ptr(armcompute.DiskAPIVersion20260302),
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
AdditionalDiskProperties: &armcompute.AdditionalDiskProperties{
ManagedDiskProperties: &armcompute.VirtualMachineDiskProperties{
NetworkAccessPolicy: to.Ptr(armcompute.VirtualMachineDiskNetworkAccessPolicyAllowPrivate),
DiskAccessID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskAccesses/myDiskAccess"),
},
},
},
Name: to.Ptr("myVMosdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
DataDisks: []*armcompute.DataDisk{
{
Lun: to.Ptr[int32](0),
Name: to.Ptr("myDataDisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesEmpty),
DiskSizeGB: to.Ptr[int32](1024),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
AdditionalDiskProperties: &armcompute.AdditionalDiskProperties{
ManagedDiskProperties: &armcompute.VirtualMachineDiskProperties{
NetworkAccessPolicy: to.Ptr(armcompute.VirtualMachineDiskNetworkAccessPolicyAllowPrivate),
DiskAccessID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskAccesses/myDiskAccess"),
Tier: to.Ptr("P30"),
},
},
},
},
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("2022-datacenter-azure-edition"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("WindowsServer"),
// },
// DiskAPIVersion: to.Ptr(armcompute.DiskAPIVersion20260302),
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
// AdditionalDiskProperties: &armcompute.AdditionalDiskProperties{
// ManagedDiskProperties: &armcompute.VirtualMachineDiskProperties{
// NetworkAccessPolicy: to.Ptr(armcompute.VirtualMachineDiskNetworkAccessPolicyAllowPrivate),
// DiskAccessID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskAccesses/myDiskAccess"),
// Tier: to.Ptr("P10"),
// },
// },
// },
// },
// DataDisks: []*armcompute.DataDisk{
// {
// Lun: to.Ptr[int32](0),
// Name: to.Ptr("myDataDisk"),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesEmpty),
// DiskSizeGB: to.Ptr[int32](1024),
// ToBeDetached: to.Ptr(false),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
// AdditionalDiskProperties: &armcompute.AdditionalDiskProperties{
// ManagedDiskProperties: &armcompute.VirtualMachineDiskProperties{
// NetworkAccessPolicy: to.Ptr(armcompute.VirtualMachineDiskNetworkAccessPolicyAllowPrivate),
// DiskAccessID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskAccesses/myDiskAccess"),
// Tier: to.Ptr("P30"),
// },
// },
// },
// },
// },
// },
// VMID: to.Ptr("b7a098cc-b0b8-46e8-a205-62f301a62a8f"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD4SV3),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Name: to.Ptr("myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithAdditionalDiskProperties.json
*/
async function createAVmWithAdditionalDiskPropertiesNetworkAccessPolicyAndTier() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D4s_v3" },
storageProfile: {
imageReference: {
sku: "2022-datacenter-azure-edition",
publisher: "MicrosoftWindowsServer",
version: "latest",
offer: "WindowsServer",
},
diskApiVersion: "2026-03-02",
osDisk: {
caching: "ReadWrite",
managedDisk: {
storageAccountType: "Premium_LRS",
additionalDiskProperties: {
managedDiskProperties: {
networkAccessPolicy: "AllowPrivate",
diskAccessId:
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskAccesses/myDiskAccess",
},
},
},
name: "myVMosdisk",
createOption: "FromImage",
},
dataDisks: [
{
lun: 0,
name: "myDataDisk",
createOption: "Empty",
diskSizeGB: 1024,
managedDisk: {
storageAccountType: "Premium_LRS",
additionalDiskProperties: {
managedDiskProperties: {
networkAccessPolicy: "AllowPrivate",
diskAccessId:
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskAccesses/myDiskAccess",
tier: "P30",
},
},
},
},
],
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2022-datacenter-azure-edition",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"diskApiVersion": "2026-03-02",
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS",
"additionalDiskProperties": {
"managedDiskProperties": {
"networkAccessPolicy": "AllowPrivate",
"diskAccessId": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskAccesses/myDiskAccess",
"tier": "P10"
}
}
}
},
"dataDisks": [
{
"lun": 0,
"name": "myDataDisk",
"createOption": "Empty",
"diskSizeGB": 1024,
"toBeDetached": false,
"managedDisk": {
"storageAccountType": "Premium_LRS",
"additionalDiskProperties": {
"managedDiskProperties": {
"networkAccessPolicy": "AllowPrivate",
"diskAccessId": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskAccesses/myDiskAccess",
"tier": "P30"
}
}
}
}
]
},
"vmId": "b7a098cc-b0b8-46e8-a205-62f301a62a8f",
"hardwareProfile": {
"vmSize": "Standard_D4s_v3"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2022-datacenter-azure-edition",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"diskApiVersion": "2026-03-02",
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS",
"additionalDiskProperties": {
"managedDiskProperties": {
"networkAccessPolicy": "AllowPrivate",
"diskAccessId": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskAccesses/myDiskAccess"
}
}
}
},
"dataDisks": [
{
"lun": 0,
"name": "myDataDisk",
"createOption": "Empty",
"diskSizeGB": 1024,
"toBeDetached": false,
"managedDisk": {
"storageAccountType": "Premium_LRS",
"additionalDiskProperties": {
"managedDiskProperties": {
"networkAccessPolicy": "AllowPrivate",
"diskAccessId": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskAccesses/myDiskAccess",
"tier": "P30"
}
}
}
}
]
},
"vmId": "b7a098cc-b0b8-46e8-a205-62f301a62a8f",
"hardwareProfile": {
"vmSize": "Standard_D4s_v3"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a vm with an extensions time budget.
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://{existing-storage-account-name}.blob.core.windows.net",
"enabled": true
}
},
"extensionsTimeBudget": "PT30M"
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.BootDiagnostics;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiagnosticsProfile;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithExtensionsTimeBudget.json
*/
/**
* Sample code: Create a vm with an extensions time budget.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAVmWithAnExtensionsTimeBudget(com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile()
.withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withExtensionsTimeBudget("PT30M"),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_with_extensions_time_budget.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": True,
"storageUri": "http://{existing-storage-account-name}.blob.core.windows.net",
}
},
"extensionsTimeBudget": "PT30M",
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithExtensionsTimeBudget.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithExtensionsTimeBudget.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMWithAnExtensionsTimeBudget() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("2016-Datacenter"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
Version: to.Ptr("latest"),
Offer: to.Ptr("WindowsServer"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
Name: to.Ptr("myVMosdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
DiagnosticsProfile: &armcompute.DiagnosticsProfile{
BootDiagnostics: &armcompute.BootDiagnostics{
StorageURI: to.Ptr("http://{existing-storage-account-name}.blob.core.windows.net"),
Enabled: to.Ptr(true),
},
},
ExtensionsTimeBudget: to.Ptr("PT30M"),
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("2016-Datacenter"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("WindowsServer"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// DiagnosticsProfile: &armcompute.DiagnosticsProfile{
// BootDiagnostics: &armcompute.BootDiagnostics{
// StorageURI: to.Ptr("http://nsgdiagnostic.blob.core.windows.net"),
// Enabled: to.Ptr(true),
// },
// },
// VMID: to.Ptr("676420ba-7a24-4bfe-80bd-9c841ee184fa"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// ExtensionsTimeBudget: to.Ptr("PT30M"),
// ProvisioningState: to.Ptr("Creating"),
// },
// Name: to.Ptr("myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithExtensionsTimeBudget.json
*/
async function createAVmWithAnExtensionsTimeBudget() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D1_v2" },
storageProfile: {
imageReference: {
sku: "2016-Datacenter",
publisher: "MicrosoftWindowsServer",
version: "latest",
offer: "WindowsServer",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Standard_LRS" },
name: "myVMosdisk",
createOption: "FromImage",
},
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
diagnosticsProfile: {
bootDiagnostics: {
storageUri: "http://{existing-storage-account-name}.blob.core.windows.net",
enabled: true,
},
},
extensionsTimeBudget: "PT30M",
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://nsgdiagnostic.blob.core.windows.net",
"enabled": true
}
},
"vmId": "676420ba-7a24-4bfe-80bd-9c841ee184fa",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"extensionsTimeBudget": "PT30M",
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://nsgdiagnostic.blob.core.windows.net",
"enabled": true
}
},
"vmId": "676420ba-7a24-4bfe-80bd-9c841ee184fa",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"extensionsTimeBudget": "PT30M",
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a vm with Application Profile.
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "{image_sku}",
"publisher": "{image_publisher}",
"version": "latest",
"offer": "{image_offer}"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"applicationProfile": {
"galleryApplications": [
{
"tags": "myTag1",
"order": 1,
"packageReferenceId": "/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdb/resourceGroups/myresourceGroupName2/providers/Microsoft.Compute/galleries/myGallery1/applications/MyApplication1/versions/1.0",
"configurationReference": "https://mystorageaccount.blob.core.windows.net/configurations/settings.config",
"treatFailureAsDeploymentFailure": false,
"enableAutomaticUpgrade": false
},
{
"packageReferenceId": "/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdg/resourceGroups/myresourceGroupName3/providers/Microsoft.Compute/galleries/myGallery2/applications/MyApplication2/versions/1.1"
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.ApplicationProfile;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VMGalleryApplication;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithApplicationProfile.json
*/
/**
* Sample code: Create a vm with Application Profile.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAVmWithApplicationProfile(com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("{image_publisher}")
.withOffer("{image_offer}").withSku("{image_sku}").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile()
.withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withApplicationProfile(new ApplicationProfile().withGalleryApplications(Arrays.asList(
new VMGalleryApplication().withTags("myTag1").withOrder(1).withPackageReferenceId(
"/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdb/resourceGroups/myresourceGroupName2/providers/Microsoft.Compute/galleries/myGallery1/applications/MyApplication1/versions/1.0")
.withConfigurationReference(
"https://mystorageaccount.blob.core.windows.net/configurations/settings.config")
.withTreatFailureAsDeploymentFailure(false).withEnableAutomaticUpgrade(false),
new VMGalleryApplication().withPackageReferenceId(
"/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdg/resourceGroups/myresourceGroupName3/providers/Microsoft.Compute/galleries/myGallery2/applications/MyApplication2/versions/1.1")))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_with_application_profile.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"applicationProfile": {
"galleryApplications": [
{
"configurationReference": "https://mystorageaccount.blob.core.windows.net/configurations/settings.config",
"enableAutomaticUpgrade": False,
"order": 1,
"packageReferenceId": "/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdb/resourceGroups/myresourceGroupName2/providers/Microsoft.Compute/galleries/myGallery1/applications/MyApplication1/versions/1.0",
"tags": "myTag1",
"treatFailureAsDeploymentFailure": False,
},
{
"packageReferenceId": "/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdg/resourceGroups/myresourceGroupName3/providers/Microsoft.Compute/galleries/myGallery2/applications/MyApplication2/versions/1.1"
},
]
},
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"offer": "{image_offer}",
"publisher": "{image_publisher}",
"sku": "{image_sku}",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithApplicationProfile.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithApplicationProfile.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMWithApplicationProfile() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("{image_sku}"),
Publisher: to.Ptr("{image_publisher}"),
Version: to.Ptr("latest"),
Offer: to.Ptr("{image_offer}"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
Name: to.Ptr("myVMosdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
},
ApplicationProfile: &armcompute.ApplicationProfile{
GalleryApplications: []*armcompute.VMGalleryApplication{
{
Tags: to.Ptr("myTag1"),
Order: to.Ptr[int32](1),
PackageReferenceID: to.Ptr("/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdb/resourceGroups/myresourceGroupName2/providers/Microsoft.Compute/galleries/myGallery1/applications/MyApplication1/versions/1.0"),
ConfigurationReference: to.Ptr("https://mystorageaccount.blob.core.windows.net/configurations/settings.config"),
TreatFailureAsDeploymentFailure: to.Ptr(false),
EnableAutomaticUpgrade: to.Ptr(false),
},
{
PackageReferenceID: to.Ptr("/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdg/resourceGroups/myresourceGroupName3/providers/Microsoft.Compute/galleries/myGallery2/applications/MyApplication2/versions/1.1"),
},
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// LinuxConfiguration: &armcompute.LinuxConfiguration{
// SSH: &armcompute.SSHConfiguration{
// PublicKeys: []*armcompute.SSHPublicKey{
// {
// Path: to.Ptr("/home/{your-username}/.ssh/authorized_keys"),
// KeyData: to.Ptr("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCeClRAk2ipUs/l5voIsDC5q9RI+YSRd1Bvd/O+axgY4WiBzG+4FwJWZm/mLLe5DoOdHQwmU2FrKXZSW4w2sYE70KeWnrFViCOX5MTVvJgPE8ClugNl8RWth/tU849DvM9sT7vFgfVSHcAS2yDRyDlueii+8nF2ym8XWAPltFVCyLHRsyBp5YPqK8JFYIa1eybKsY3hEAxRCA+/7bq8et+Gj3coOsuRmrehav7rE6N12Pb80I6ofa6SM5XNYq4Xk0iYNx7R3kdz0Jj9XgZYWjAHjJmT0gTRoOnt6upOuxK7xI/ykWrllgpXrCPu3Ymz+c+ujaqcxDopnAl2lmf69/J1"),
// },
// },
// },
// DisablePasswordAuthentication: to.Ptr(true),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("16.04-LTS"),
// Publisher: to.Ptr("Canonical"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("UbuntuServer"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// ApplicationProfile: &armcompute.ApplicationProfile{
// GalleryApplications: []*armcompute.VMGalleryApplication{
// {
// Tags: to.Ptr("myTag1"),
// Order: to.Ptr[int32](1),
// PackageReferenceID: to.Ptr("/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdb/resourceGroups/myresourceGroupName2/providers/Microsoft.Compute/galleries/myGallery1/applications/MyApplication1/versions/1.0"),
// ConfigurationReference: to.Ptr("https://mystorageaccount.blob.core.windows.net/configurations/settings.config"),
// },
// {
// PackageReferenceID: to.Ptr("/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdg/resourceGroups/myresourceGroupName3/providers/Microsoft.Compute/galleries/myGallery2/applications/MyApplication2/versions/1.1"),
// },
// },
// },
// VMID: to.Ptr("e0de9b84-a506-4b95-9623-00a425d05c90"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Name: to.Ptr("myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithApplicationProfile.json
*/
async function createAVmWithApplicationProfile() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D1_v2" },
storageProfile: {
imageReference: {
sku: "{image_sku}",
publisher: "{image_publisher}",
version: "latest",
offer: "{image_offer}",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Standard_LRS" },
name: "myVMosdisk",
createOption: "FromImage",
},
},
applicationProfile: {
galleryApplications: [
{
tags: "myTag1",
order: 1,
packageReferenceId:
"/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdb/resourceGroups/myresourceGroupName2/providers/Microsoft.Compute/galleries/myGallery1/applications/MyApplication1/versions/1.0",
configurationReference:
"https://mystorageaccount.blob.core.windows.net/configurations/settings.config",
treatFailureAsDeploymentFailure: false,
enableAutomaticUpgrade: false,
},
{
packageReferenceId:
"/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdg/resourceGroups/myresourceGroupName3/providers/Microsoft.Compute/galleries/myGallery2/applications/MyApplication2/versions/1.1",
},
],
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"ssh": {
"publicKeys": [
{
"path": "/home/{your-username}/.ssh/authorized_keys",
"keyData": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCeClRAk2ipUs/l5voIsDC5q9RI+YSRd1Bvd/O+axgY4WiBzG+4FwJWZm/mLLe5DoOdHQwmU2FrKXZSW4w2sYE70KeWnrFViCOX5MTVvJgPE8ClugNl8RWth/tU849DvM9sT7vFgfVSHcAS2yDRyDlueii+8nF2ym8XWAPltFVCyLHRsyBp5YPqK8JFYIa1eybKsY3hEAxRCA+/7bq8et+Gj3coOsuRmrehav7rE6N12Pb80I6ofa6SM5XNYq4Xk0iYNx7R3kdz0Jj9XgZYWjAHjJmT0gTRoOnt6upOuxK7xI/ykWrllgpXrCPu3Ymz+c+ujaqcxDopnAl2lmf69/J1"
}
]
},
"disablePasswordAuthentication": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "16.04-LTS",
"publisher": "Canonical",
"version": "latest",
"offer": "UbuntuServer"
},
"osDisk": {
"osType": "Linux",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"applicationProfile": {
"galleryApplications": [
{
"tags": "myTag1",
"order": 1,
"packageReferenceId": "/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdb/resourceGroups/myresourceGroupName2/providers/Microsoft.Compute/galleries/myGallery1/applications/MyApplication1/versions/1.0",
"configurationReference": "https://mystorageaccount.blob.core.windows.net/configurations/settings.config"
},
{
"packageReferenceId": "/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdg/resourceGroups/myresourceGroupName3/providers/Microsoft.Compute/galleries/myGallery2/applications/MyApplication2/versions/1.1"
}
]
},
"vmId": "e0de9b84-a506-4b95-9623-00a425d05c90",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"ssh": {
"publicKeys": [
{
"path": "/home/{your-username}/.ssh/authorized_keys",
"keyData": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCeClRAk2ipUs/l5voIsDC5q9RI+YSRd1Bvd/O+axgY4WiBzG+4FwJWZm/mLLe5DoOdHQwmU2FrKXZSW4w2sYE70KeWnrFViCOX5MTVvJgPE8ClugNl8RWth/tU849DvM9sT7vFgfVSHcAS2yDRyDlueii+8nF2ym8XWAPltFVCyLHRsyBp5YPqK8JFYIa1eybKsY3hEAxRCA+/7bq8et+Gj3coOsuRmrehav7rE6N12Pb80I6ofa6SM5XNYq4Xk0iYNx7R3kdz0Jj9XgZYWjAHjJmT0gTRoOnt6upOuxK7xI/ykWrllgpXrCPu3Ymz+c+ujaqcxDopnAl2lmf69/J1"
}
]
},
"disablePasswordAuthentication": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "16.04-LTS",
"publisher": "Canonical",
"version": "latest",
"offer": "UbuntuServer"
},
"osDisk": {
"osType": "Linux",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"applicationProfile": {
"galleryApplications": [
{
"tags": "myTag1",
"order": 1,
"packageReferenceId": "/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdb/resourceGroups/myresourceGroupName2/providers/Microsoft.Compute/galleries/myGallery1/applications/MyApplication1/versions/1.0",
"configurationReference": "https://mystorageaccount.blob.core.windows.net/configurations/settings.config"
},
{
"packageReferenceId": "/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdg/resourceGroups/myresourceGroupName3/providers/Microsoft.Compute/galleries/myGallery2/applications/MyApplication2/versions/1.1"
}
]
},
"vmId": "e0de9b84-a506-4b95-9623-00a425d05c90",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a VM with automatic zone placement
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus2",
"plan": {
"publisher": "microsoft-ads",
"product": "windows-data-science-vm",
"name": "windows2016"
},
"properties": {
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "windows2016",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "windows-data-science-vm"
},
"osDisk": {
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
},
"placement": {
"zonePlacementPolicy": "Any",
"includeZones": [
"1",
"3"
]
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.Placement;
import com.azure.resourcemanager.compute.models.Plan;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import com.azure.resourcemanager.compute.models.ZonePlacementPolicyType;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithPlacement.json
*/
/**
* Sample code: Create a VM with automatic zone placement.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAVMWithAutomaticZonePlacement(com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus2")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withPlacement(new Placement().withZonePlacementPolicy(ZonePlacementPolicyType.ANY)
.withIncludeZones(Arrays.asList("1", "3")))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_DS1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile()
.withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_with_placement.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus2",
"placement": {"includeZones": ["1", "3"], "zonePlacementPolicy": "Any"},
"plan": {"name": "windows2016", "product": "windows-data-science-vm", "publisher": "microsoft-ads"},
"properties": {
"hardwareProfile": {"vmSize": "Standard_DS1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"offer": "windows-data-science-vm",
"publisher": "microsoft-ads",
"sku": "windows2016",
"version": "latest",
},
"osDisk": {
"caching": "ReadOnly",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithPlacement.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithPlacement.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMWithAutomaticZonePlacement() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus2"),
Plan: &armcompute.Plan{
Publisher: to.Ptr("microsoft-ads"),
Product: to.Ptr("windows-data-science-vm"),
Name: to.Ptr("windows2016"),
},
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("windows2016"),
Publisher: to.Ptr("microsoft-ads"),
Version: to.Ptr("latest"),
Offer: to.Ptr("windows-data-science-vm"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadOnly),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
Name: to.Ptr("myVMosdisk"),
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
Placement: &armcompute.Placement{
ZonePlacementPolicy: to.Ptr(armcompute.ZonePlacementPolicyTypeAny),
IncludeZones: []*string{
to.Ptr("1"),
to.Ptr("3"),
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("standard-data-science-vm"),
// Publisher: to.Ptr("microsoft-ads"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("standard-data-science-vm"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadOnly),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// VMID: to.Ptr("5c0d55a7-c407-4ed6-bf7d-ddb810267c85"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Zones: []*string{
// to.Ptr("3"),
// },
// Placement: &armcompute.Placement{
// ZonePlacementPolicy: to.Ptr(armcompute.ZonePlacementPolicyTypeAny),
// IncludeZones: []*string{
// to.Ptr("1"),
// to.Ptr("3"),
// },
// },
// Plan: &armcompute.Plan{
// Publisher: to.Ptr("microsoft-ads"),
// Product: to.Ptr("standard-data-science-vm"),
// Name: to.Ptr("standard-data-science-vm"),
// },
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus2"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithPlacement.json
*/
async function createAVMWithAutomaticZonePlacement() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus2",
plan: { publisher: "microsoft-ads", product: "windows-data-science-vm", name: "windows2016" },
hardwareProfile: { vmSize: "Standard_DS1_v2" },
storageProfile: {
imageReference: {
sku: "windows2016",
publisher: "microsoft-ads",
version: "latest",
offer: "windows-data-science-vm",
},
osDisk: {
caching: "ReadOnly",
managedDisk: { storageAccountType: "Standard_LRS" },
createOption: "FromImage",
name: "myVMosdisk",
},
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
placement: { zonePlacementPolicy: "Any", includeZones: ["1", "3"] },
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "standard-data-science-vm",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "standard-data-science-vm"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"zones": [
"3"
],
"placement": {
"zonePlacementPolicy": "Any",
"includeZones": [
"1",
"3"
]
},
"plan": {
"publisher": "microsoft-ads",
"product": "standard-data-science-vm",
"name": "standard-data-science-vm"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus2"
}
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "standard-data-science-vm",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "standard-data-science-vm"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"zones": [
"3"
],
"placement": {
"zonePlacementPolicy": "Any",
"includeZones": [
"1",
"3"
]
},
"plan": {
"publisher": "microsoft-ads",
"product": "standard-data-science-vm",
"name": "standard-data-science-vm"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus2"
}
Create a vm with boot diagnostics.
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://{existing-storage-account-name}.blob.core.windows.net",
"enabled": true
}
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.BootDiagnostics;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiagnosticsProfile;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithBootDiagnostics.json
*/
/**
* Sample code: Create a vm with boot diagnostics.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAVmWithBootDiagnostics(com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile()
.withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net"))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_with_boot_diagnostics.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": True,
"storageUri": "http://{existing-storage-account-name}.blob.core.windows.net",
}
},
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithBootDiagnostics.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithBootDiagnostics.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMWithBootDiagnostics() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("2016-Datacenter"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
Version: to.Ptr("latest"),
Offer: to.Ptr("WindowsServer"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
Name: to.Ptr("myVMosdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
DiagnosticsProfile: &armcompute.DiagnosticsProfile{
BootDiagnostics: &armcompute.BootDiagnostics{
StorageURI: to.Ptr("http://{existing-storage-account-name}.blob.core.windows.net"),
Enabled: to.Ptr(true),
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("2016-Datacenter"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("WindowsServer"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// DiagnosticsProfile: &armcompute.DiagnosticsProfile{
// BootDiagnostics: &armcompute.BootDiagnostics{
// StorageURI: to.Ptr("http://nsgdiagnostic.blob.core.windows.net"),
// Enabled: to.Ptr(true),
// },
// },
// VMID: to.Ptr("676420ba-7a24-4bfe-80bd-9c841ee184fa"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Name: to.Ptr("myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithBootDiagnostics.json
*/
async function createAVmWithBootDiagnostics() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D1_v2" },
storageProfile: {
imageReference: {
sku: "2016-Datacenter",
publisher: "MicrosoftWindowsServer",
version: "latest",
offer: "WindowsServer",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Standard_LRS" },
name: "myVMosdisk",
createOption: "FromImage",
},
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
diagnosticsProfile: {
bootDiagnostics: {
storageUri: "http://{existing-storage-account-name}.blob.core.windows.net",
enabled: true,
},
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://nsgdiagnostic.blob.core.windows.net",
"enabled": true
}
},
"vmId": "676420ba-7a24-4bfe-80bd-9c841ee184fa",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://nsgdiagnostic.blob.core.windows.net",
"enabled": true
}
},
"vmId": "676420ba-7a24-4bfe-80bd-9c841ee184fa",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a VM with capacity reservation assignment disabled
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
}
},
"capacityReservation": {
"disableCapacityReservationAssignment": true
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.CapacityReservationProfile;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithCapacityReservationAssignmentDisabled.json
*/
/**
* Sample code: Create a VM with capacity reservation assignment disabled.
*
* @param manager Entry point to ComputeManager.
*/
public static void
createAVMWithCapacityReservationAssignmentDisabled(com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_DS1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile()
.withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withCapacityReservation(
new CapacityReservationProfile().withDisableCapacityReservationAssignment(true)),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_with_capacity_reservation_assignment_disabled.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"capacityReservation": {"disableCapacityReservationAssignment": True},
"hardwareProfile": {"vmSize": "Standard_DS1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithCapacityReservationAssignmentDisabled.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithCapacityReservationAssignmentDisabled.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMWithCapacityReservationAssignmentDisabled() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("2016-Datacenter"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
Version: to.Ptr("latest"),
Offer: to.Ptr("WindowsServer"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
Name: to.Ptr("myVMosdisk"),
},
},
CapacityReservation: &armcompute.CapacityReservationProfile{
DisableCapacityReservationAssignment: to.Ptr(true),
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// },
// },
// CapacityReservation: &armcompute.CapacityReservationProfile{
// DisableCapacityReservationAssignment: to.Ptr(true),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("2016-Datacenter"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("WindowsServer"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// VMID: to.Ptr("5c0d55a7-c407-4ed6-bf7d-ddb810267c85"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithCapacityReservationAssignmentDisabled.json
*/
async function createAVMWithCapacityReservationAssignmentDisabled() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_DS1_v2" },
storageProfile: {
imageReference: {
sku: "2016-Datacenter",
publisher: "MicrosoftWindowsServer",
version: "latest",
offer: "WindowsServer",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Standard_LRS" },
createOption: "FromImage",
name: "myVMosdisk",
},
},
capacityReservation: { disableCapacityReservationAssignment: true },
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"capacityReservation": {
"disableCapacityReservationAssignment": true
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"capacityReservation": {
"disableCapacityReservationAssignment": true
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
Create a vm with data disks using 'Copy' and 'Restore' options.
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D2_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
},
"dataDisks": [
{
"diskSizeGB": 1023,
"createOption": "Copy",
"sourceResource": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/{existing-snapshot-name}"
},
"lun": 0
},
{
"diskSizeGB": 1023,
"createOption": "Copy",
"sourceResource": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-disk-name}"
},
"lun": 1
},
{
"diskSizeGB": 1023,
"createOption": "Restore",
"sourceResource": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/restorePointCollections/{existing-rpc-name}/restorePoints/{existing-rp-name}/diskRestorePoints/{existing-disk-restore-point-name}"
},
"lun": 2
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DataDisk;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithDataDisksFromSourceResource.json
*/
/**
* Sample code: Create a vm with data disks using 'Copy' and 'Restore' options.
*
* @param manager Entry point to ComputeManager.
*/
public static void
createAVmWithDataDisksUsingCopyAndRestoreOptions(com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines()
.createOrUpdate("myResourceGroup", "myVM", new VirtualMachineInner()
.withLocation(
"westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2_V2))
.withStorageProfile(new StorageProfile().withImageReference(new ImageReference()
.withPublisher("MicrosoftWindowsServer").withOffer("WindowsServer").withSku("2016-Datacenter")
.withVersion("latest")).withOsDisk(new OSDisk().withName("myVMosdisk")
.withCaching(CachingTypes.READ_WRITE).withCreateOption(
DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS)))
.withDataDisks(Arrays.asList(new DataDisk().withLun(0).withCreateOption(DiskCreateOptionTypes.COPY)
.withDiskSizeGB(1023)
.withSourceResource(new ApiEntityReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/{existing-snapshot-name}")),
new DataDisk().withLun(1).withCreateOption(DiskCreateOptionTypes.COPY).withDiskSizeGB(1023)
.withSourceResource(new ApiEntityReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-disk-name}")),
new DataDisk().withLun(2).withCreateOption(DiskCreateOptionTypes.RESTORE).withDiskSizeGB(1023)
.withSourceResource(new ApiEntityReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/restorePointCollections/{existing-rpc-name}/restorePoints/{existing-rp-name}/diskRestorePoints/{existing-disk-restore-point-name}")))))
.withOsProfile(new OSProfile()
.withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_with_data_disks_from_source_resource.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D2_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"dataDisks": [
{
"createOption": "Copy",
"diskSizeGB": 1023,
"lun": 0,
"sourceResource": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/{existing-snapshot-name}"
},
},
{
"createOption": "Copy",
"diskSizeGB": 1023,
"lun": 1,
"sourceResource": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-disk-name}"
},
},
{
"createOption": "Restore",
"diskSizeGB": 1023,
"lun": 2,
"sourceResource": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/restorePointCollections/{existing-rpc-name}/restorePoints/{existing-rp-name}/diskRestorePoints/{existing-disk-restore-point-name}"
},
},
],
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithDataDisksFromSourceResource.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithDataDisksFromSourceResource.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMWithDataDisksUsingCopyAndRestoreOptions() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2V2),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("2016-Datacenter"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
Version: to.Ptr("latest"),
Offer: to.Ptr("WindowsServer"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
Name: to.Ptr("myVMosdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
DataDisks: []*armcompute.DataDisk{
{
DiskSizeGB: to.Ptr[int32](1023),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesCopy),
SourceResource: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/{existing-snapshot-name}"),
},
Lun: to.Ptr[int32](0),
},
{
DiskSizeGB: to.Ptr[int32](1023),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesCopy),
SourceResource: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-disk-name}"),
},
Lun: to.Ptr[int32](1),
},
{
DiskSizeGB: to.Ptr[int32](1023),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesRestore),
SourceResource: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/restorePointCollections/{existing-rpc-name}/restorePoints/{existing-rp-name}/diskRestorePoints/{existing-disk-restore-point-name}"),
},
Lun: to.Ptr[int32](2),
},
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("2016-Datacenter"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("WindowsServer"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// },
// DataDisks: []*armcompute.DataDisk{
// {
// Caching: to.Ptr(armcompute.CachingTypesNone),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesCopy),
// SourceResource: &armcompute.APIEntityReference{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/{existing-snapshot-name}"),
// },
// Lun: to.Ptr[int32](0),
// DiskSizeGB: to.Ptr[int32](1023),
// },
// {
// Caching: to.Ptr(armcompute.CachingTypesNone),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesCopy),
// SourceResource: &armcompute.APIEntityReference{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-disk-name}"),
// },
// Lun: to.Ptr[int32](1),
// DiskSizeGB: to.Ptr[int32](1023),
// },
// {
// Caching: to.Ptr(armcompute.CachingTypesNone),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesRestore),
// SourceResource: &armcompute.APIEntityReference{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/restorePointCollections/{existing-rpc-name}/restorePoints/{existing-rp-name}/diskRestorePoints/{existing-disk-restore-point-name}"),
// },
// Lun: to.Ptr[int32](2),
// DiskSizeGB: to.Ptr[int32](1023),
// },
// },
// },
// VMID: to.Ptr("3906fef9-a1e5-4b83-a8a8-540858b41df0"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2V2),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Name: to.Ptr("myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithDataDisksFromSourceResource.json
*/
async function createAVmWithDataDisksUsingCopyAndRestoreOptions() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D2_v2" },
storageProfile: {
imageReference: {
sku: "2016-Datacenter",
publisher: "MicrosoftWindowsServer",
version: "latest",
offer: "WindowsServer",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Standard_LRS" },
name: "myVMosdisk",
createOption: "FromImage",
},
dataDisks: [
{
diskSizeGB: 1023,
createOption: "Copy",
sourceResource: {
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/{existing-snapshot-name}",
},
lun: 0,
},
{
diskSizeGB: 1023,
createOption: "Copy",
sourceResource: {
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-disk-name}",
},
lun: 1,
},
{
diskSizeGB: 1023,
createOption: "Restore",
sourceResource: {
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/restorePointCollections/{existing-rpc-name}/restorePoints/{existing-rp-name}/diskRestorePoints/{existing-disk-restore-point-name}",
},
lun: 2,
},
],
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": [
{
"caching": "None",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "Copy",
"sourceResource": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/{existing-snapshot-name}"
},
"lun": 0,
"diskSizeGB": 1023
},
{
"caching": "None",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "Copy",
"sourceResource": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-disk-name}"
},
"lun": 1,
"diskSizeGB": 1023
},
{
"caching": "None",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "Restore",
"sourceResource": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/restorePointCollections/{existing-rpc-name}/restorePoints/{existing-rp-name}/diskRestorePoints/{existing-disk-restore-point-name}"
},
"lun": 2,
"diskSizeGB": 1023
}
]
},
"vmId": "3906fef9-a1e5-4b83-a8a8-540858b41df0",
"hardwareProfile": {
"vmSize": "Standard_D2_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": [
{
"caching": "None",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "Copy",
"sourceResource": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/{existing-snapshot-name}"
},
"lun": 0,
"diskSizeGB": 1023,
"toBeDetached": false
},
{
"caching": "None",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "Copy",
"sourceResource": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-disk-name}"
},
"lun": 1,
"diskSizeGB": 1023,
"toBeDetached": false
},
{
"caching": "None",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "Restore",
"sourceResource": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/restorePointCollections/{existing-rpc-name}/restorePoints/{existing-rp-name}/diskRestorePoints/{existing-disk-restore-point-name}"
},
"lun": 2,
"diskSizeGB": 1023,
"toBeDetached": false
}
]
},
"vmId": "3906fef9-a1e5-4b83-a8a8-540858b41df0",
"hardwareProfile": {
"vmSize": "Standard_D2_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a VM with Deterministic Processor Mode
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_E2pds_v8",
"processorMode": "Deterministic"
},
"storageProfile": {
"imageReference": {
"sku": "2019-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Premium_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.ProcessorMode;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithDeterministicProcessorMode.json
*/
/**
* Sample code: Create a VM with Deterministic Processor Mode.
*
* @param manager Entry point to ComputeManager.
*/
public static void
createAVMWithDeterministicProcessorMode(com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(
new HardwareProfile().withVmSize(VirtualMachineSizeTypes.fromString("Standard_E2pds_v8"))
.withProcessorMode(ProcessorMode.DETERMINISTIC))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2019-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile()
.withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_with_deterministic_processor_mode.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"processorMode": "Deterministic", "vmSize": "Standard_E2pds_v8"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2019-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Premium_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithDeterministicProcessorMode.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithDeterministicProcessorMode.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMWithDeterministicProcessorMode() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypes("Standard_E2pds_v8")),
ProcessorMode: to.Ptr(armcompute.ProcessorModeDeterministic),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("2019-Datacenter"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
Version: to.Ptr("latest"),
Offer: to.Ptr("WindowsServer"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
},
Name: to.Ptr("myVMosdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("2019-Datacenter"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("WindowsServer"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
// },
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypes("Standard_E2pds_v8")),
// ProcessorMode: to.Ptr(armcompute.ProcessorModeDeterministic),
// },
// ProvisioningState: to.Ptr("Updating"),
// },
// Name: to.Ptr("myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithDeterministicProcessorMode.json
*/
async function createAVMWithDeterministicProcessorMode() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_E2pds_v8", processorMode: "Deterministic" },
storageProfile: {
imageReference: {
sku: "2019-Datacenter",
publisher: "MicrosoftWindowsServer",
version: "latest",
offer: "WindowsServer",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Premium_LRS" },
name: "myVMosdisk",
createOption: "FromImage",
},
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2019-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"hardwareProfile": {
"vmSize": "Standard_E2pds_v8",
"processorMode": "Deterministic"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2019-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"hardwareProfile": {
"vmSize": "Standard_E2pds_v8",
"processorMode": "Deterministic"
},
"provisioningState": "Updating"
},
"name": "myVM",
"location": "westus"
}
Create a VM with Disk Controller Type
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D4_v3"
},
"scheduledEventsPolicy": {
"scheduledEventsAdditionalPublishingTargets": {
"eventGridAndResourceGraph": {
"enable": true,
"scheduledEventsApiVersion": "2020-07-01"
}
},
"userInitiatedRedeploy": {
"automaticallyApprove": true
},
"userInitiatedReboot": {
"automaticallyApprove": true
},
"allInstancesDown": {
"automaticallyApprove": true
}
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
},
"diskControllerType": "NVMe"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://{existing-storage-account-name}.blob.core.windows.net",
"enabled": true
}
},
"userData": "U29tZSBDdXN0b20gRGF0YQ=="
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.AllInstancesDown;
import com.azure.resourcemanager.compute.models.BootDiagnostics;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiagnosticsProfile;
import com.azure.resourcemanager.compute.models.DiskControllerTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.EventGridAndResourceGraph;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.ScheduledEventsAdditionalPublishingTargets;
import com.azure.resourcemanager.compute.models.ScheduledEventsPolicy;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.UserInitiatedReboot;
import com.azure.resourcemanager.compute.models.UserInitiatedRedeploy;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithDiskControllerType.json
*/
/**
* Sample code: Create a VM with Disk Controller Type.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAVMWithDiskControllerType(com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM", new VirtualMachineInner()
.withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D4_V3))
.withScheduledEventsPolicy(new ScheduledEventsPolicy()
.withUserInitiatedRedeploy(new UserInitiatedRedeploy().withAutomaticallyApprove(true))
.withUserInitiatedReboot(new UserInitiatedReboot().withAutomaticallyApprove(true))
.withScheduledEventsAdditionalPublishingTargets(
new ScheduledEventsAdditionalPublishingTargets().withEventGridAndResourceGraph(
new EventGridAndResourceGraph().withEnable(true).withScheduledEventsApiVersion("2020-07-01")))
.withAllInstancesDown(new AllInstancesDown().withAutomaticallyApprove(true)))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS)))
.withDiskControllerType(DiskControllerTypes.NVME))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics().withEnabled(true)
.withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withUserData("U29tZSBDdXN0b20gRGF0YQ=="), null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_with_disk_controller_type.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": True,
"storageUri": "http://{existing-storage-account-name}.blob.core.windows.net",
}
},
"hardwareProfile": {"vmSize": "Standard_D4_v3"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"scheduledEventsPolicy": {
"allInstancesDown": {"automaticallyApprove": True},
"scheduledEventsAdditionalPublishingTargets": {
"eventGridAndResourceGraph": {"enable": True, "scheduledEventsApiVersion": "2020-07-01"}
},
"userInitiatedReboot": {"automaticallyApprove": True},
"userInitiatedRedeploy": {"automaticallyApprove": True},
},
"storageProfile": {
"diskControllerType": "NVMe",
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
"userData": "U29tZSBDdXN0b20gRGF0YQ==",
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithDiskControllerType.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithDiskControllerType.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMWithDiskControllerType() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD4V3),
},
ScheduledEventsPolicy: &armcompute.ScheduledEventsPolicy{
ScheduledEventsAdditionalPublishingTargets: &armcompute.ScheduledEventsAdditionalPublishingTargets{
EventGridAndResourceGraph: &armcompute.EventGridAndResourceGraph{
Enable: to.Ptr(true),
ScheduledEventsAPIVersion: to.Ptr("2020-07-01"),
},
},
UserInitiatedRedeploy: &armcompute.UserInitiatedRedeploy{
AutomaticallyApprove: to.Ptr(true),
},
UserInitiatedReboot: &armcompute.UserInitiatedReboot{
AutomaticallyApprove: to.Ptr(true),
},
AllInstancesDown: &armcompute.AllInstancesDown{
AutomaticallyApprove: to.Ptr(true),
},
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("2016-Datacenter"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
Version: to.Ptr("latest"),
Offer: to.Ptr("WindowsServer"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
Name: to.Ptr("myVMosdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
DiskControllerType: to.Ptr(armcompute.DiskControllerTypesNVMe),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
DiagnosticsProfile: &armcompute.DiagnosticsProfile{
BootDiagnostics: &armcompute.BootDiagnostics{
StorageURI: to.Ptr("http://{existing-storage-account-name}.blob.core.windows.net"),
Enabled: to.Ptr(true),
},
},
UserData: to.Ptr("U29tZSBDdXN0b20gRGF0YQ=="),
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("2016-Datacenter"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("WindowsServer"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// },
// DataDisks: []*armcompute.DataDisk{
// },
// DiskControllerType: to.Ptr(armcompute.DiskControllerTypesNVMe),
// },
// DiagnosticsProfile: &armcompute.DiagnosticsProfile{
// BootDiagnostics: &armcompute.BootDiagnostics{
// StorageURI: to.Ptr("http://nsgdiagnostic.blob.core.windows.net"),
// Enabled: to.Ptr(true),
// },
// },
// VMID: to.Ptr("676420ba-7a24-4bfe-80bd-9c841ee184fa"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD4V3),
// },
// ScheduledEventsPolicy: &armcompute.ScheduledEventsPolicy{
// ScheduledEventsAdditionalPublishingTargets: &armcompute.ScheduledEventsAdditionalPublishingTargets{
// EventGridAndResourceGraph: &armcompute.EventGridAndResourceGraph{
// Enable: to.Ptr(true),
// ScheduledEventsAPIVersion: to.Ptr("2020-07-01"),
// },
// },
// UserInitiatedRedeploy: &armcompute.UserInitiatedRedeploy{
// AutomaticallyApprove: to.Ptr(true),
// },
// UserInitiatedReboot: &armcompute.UserInitiatedReboot{
// AutomaticallyApprove: to.Ptr(true),
// },
// AllInstancesDown: &armcompute.AllInstancesDown{
// AutomaticallyApprove: to.Ptr(true),
// },
// },
// ProvisioningState: to.Ptr("Updating"),
// },
// Name: to.Ptr("myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithDiskControllerType.json
*/
async function createAVMWithDiskControllerType() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D4_v3" },
scheduledEventsPolicy: {
scheduledEventsAdditionalPublishingTargets: {
eventGridAndResourceGraph: { enable: true, scheduledEventsApiVersion: "2020-07-01" },
},
userInitiatedRedeploy: { automaticallyApprove: true },
userInitiatedReboot: { automaticallyApprove: true },
allInstancesDown: { automaticallyApprove: true },
},
storageProfile: {
imageReference: {
sku: "2016-Datacenter",
publisher: "MicrosoftWindowsServer",
version: "latest",
offer: "WindowsServer",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Standard_LRS" },
name: "myVMosdisk",
createOption: "FromImage",
},
diskControllerType: "NVMe",
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
diagnosticsProfile: {
bootDiagnostics: {
storageUri: "http://{existing-storage-account-name}.blob.core.windows.net",
enabled: true,
},
},
userData: "U29tZSBDdXN0b20gRGF0YQ==",
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": [],
"diskControllerType": "NVMe"
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://nsgdiagnostic.blob.core.windows.net",
"enabled": true
}
},
"vmId": "676420ba-7a24-4bfe-80bd-9c841ee184fa",
"hardwareProfile": {
"vmSize": "Standard_D4_v3"
},
"scheduledEventsPolicy": {
"scheduledEventsAdditionalPublishingTargets": {
"eventGridAndResourceGraph": {
"enable": true,
"scheduledEventsApiVersion": "2020-07-01"
}
},
"userInitiatedRedeploy": {
"automaticallyApprove": true
},
"userInitiatedReboot": {
"automaticallyApprove": true
},
"allInstancesDown": {
"automaticallyApprove": true
}
},
"provisioningState": "Updating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": [],
"diskControllerType": "NVMe"
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://nsgdiagnostic.blob.core.windows.net",
"enabled": true
}
},
"vmId": "676420ba-7a24-4bfe-80bd-9c841ee184fa",
"hardwareProfile": {
"vmSize": "Standard_D4_v3"
},
"scheduledEventsPolicy": {
"scheduledEventsAdditionalPublishingTargets": {
"eventGridAndResourceGraph": {
"enable": true,
"scheduledEventsApiVersion": "2020-07-01"
}
},
"userInitiatedRedeploy": {
"automaticallyApprove": true
},
"userInitiatedReboot": {
"automaticallyApprove": true
},
"allInstancesDown": {
"automaticallyApprove": true
}
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a vm with DiskEncryptionSet resource id in the os disk and data disk.
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS",
"diskEncryptionSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
}
},
"name": "myVMosdisk",
"createOption": "FromImage"
},
"dataDisks": [
{
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS",
"diskEncryptionSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
}
},
"diskSizeGB": 1023,
"createOption": "Empty",
"lun": 0
},
{
"caching": "ReadWrite",
"managedDisk": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-managed-disk-name}",
"storageAccountType": "Standard_LRS",
"diskEncryptionSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
}
},
"diskSizeGB": 1023,
"createOption": "Attach",
"lun": 1
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DataDisk;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.DiskEncryptionSetParameters;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithDiskEncryptionSetResource.json
*/
/**
* Sample code: Create a vm with DiskEncryptionSet resource id in the os disk and data disk.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAVmWithDiskEncryptionSetResourceIdInTheOsDiskAndDataDisk(
com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM", new VirtualMachineInner()
.withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withImageReference(new ImageReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(new ManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS)
.withDiskEncryptionSet(new DiskEncryptionSetParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"))))
.withDataDisks(Arrays.asList(new DataDisk().withLun(0).withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023)
.withManagedDisk(new ManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS)
.withDiskEncryptionSet(new DiskEncryptionSetParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"))),
new DataDisk().withLun(1).withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.ATTACH).withDiskSizeGB(1023)
.withManagedDisk(new ManagedDiskParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-managed-disk-name}")
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS)
.withDiskEncryptionSet(new DiskEncryptionSetParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"))))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_with_disk_encryption_set_resource.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"dataDisks": [
{
"caching": "ReadWrite",
"createOption": "Empty",
"diskSizeGB": 1023,
"lun": 0,
"managedDisk": {
"diskEncryptionSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
},
"storageAccountType": "Standard_LRS",
},
},
{
"caching": "ReadWrite",
"createOption": "Attach",
"diskSizeGB": 1023,
"lun": 1,
"managedDisk": {
"diskEncryptionSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
},
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-managed-disk-name}",
"storageAccountType": "Standard_LRS",
},
},
],
"imageReference": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}"
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {
"diskEncryptionSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
},
"storageAccountType": "Standard_LRS",
},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithDiskEncryptionSetResource.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithDiskEncryptionSetResource.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMWithDiskEncryptionSetResourceIdInTheOSDiskAndDataDisk() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
DiskEncryptionSet: &armcompute.DiskEncryptionSetParameters{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"),
},
},
Name: to.Ptr("myVMosdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
DataDisks: []*armcompute.DataDisk{
{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
DiskEncryptionSet: &armcompute.DiskEncryptionSetParameters{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"),
},
},
DiskSizeGB: to.Ptr[int32](1023),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesEmpty),
Lun: to.Ptr[int32](0),
},
{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-managed-disk-name}"),
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
DiskEncryptionSet: &armcompute.DiskEncryptionSetParameters{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"),
},
},
DiskSizeGB: to.Ptr[int32](1023),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesAttach),
Lun: to.Ptr[int32](1),
},
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// LinuxConfiguration: &armcompute.LinuxConfiguration{
// DisablePasswordAuthentication: to.Ptr(false),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/nsgcustom"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// DiskSizeGB: to.Ptr[int32](30),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// DiskEncryptionSet: &armcompute.DiskEncryptionSetParameters{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskencryptionset-name}"),
// },
// },
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
// },
// DataDisks: []*armcompute.DataDisk{
// {
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// DiskEncryptionSet: &armcompute.DiskEncryptionSetParameters{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"),
// },
// },
// DiskSizeGB: to.Ptr[int32](1023),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesEmpty),
// Lun: to.Ptr[int32](0),
// },
// {
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-managed-disk-name}"),
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// DiskEncryptionSet: &armcompute.DiskEncryptionSetParameters{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"),
// },
// },
// DiskSizeGB: to.Ptr[int32](1023),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesAttach),
// Lun: to.Ptr[int32](1),
// },
// },
// },
// VMID: to.Ptr("71aa3d5a-d73d-4970-9182-8580433b2865"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Name: to.Ptr("myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithDiskEncryptionSetResource.json
*/
async function createAVmWithDiskEncryptionSetResourceIdInTheOsDiskAndDataDisk() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D1_v2" },
storageProfile: {
imageReference: {
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}",
},
osDisk: {
caching: "ReadWrite",
managedDisk: {
storageAccountType: "Standard_LRS",
diskEncryptionSet: {
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}",
},
},
name: "myVMosdisk",
createOption: "FromImage",
},
dataDisks: [
{
caching: "ReadWrite",
managedDisk: {
storageAccountType: "Standard_LRS",
diskEncryptionSet: {
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}",
},
},
diskSizeGB: 1023,
createOption: "Empty",
lun: 0,
},
{
caching: "ReadWrite",
managedDisk: {
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-managed-disk-name}",
storageAccountType: "Standard_LRS",
diskEncryptionSet: {
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}",
},
},
diskSizeGB: 1023,
createOption: "Attach",
lun: 1,
},
],
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"disablePasswordAuthentication": false
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/nsgcustom"
},
"osDisk": {
"name": "myVMosdisk",
"diskSizeGB": 30,
"managedDisk": {
"storageAccountType": "Standard_LRS",
"diskEncryptionSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskencryptionset-name}"
}
},
"caching": "ReadWrite",
"createOption": "FromImage",
"osType": "Linux"
},
"dataDisks": [
{
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS",
"diskEncryptionSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
}
},
"diskSizeGB": 1023,
"createOption": "Empty",
"lun": 0
},
{
"caching": "ReadWrite",
"managedDisk": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-managed-disk-name}",
"storageAccountType": "Standard_LRS",
"diskEncryptionSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
}
},
"diskSizeGB": 1023,
"createOption": "Attach",
"lun": 1
}
]
},
"vmId": "71aa3d5a-d73d-4970-9182-8580433b2865",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"disablePasswordAuthentication": false
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/nsgcustom"
},
"osDisk": {
"name": "myVMosdisk",
"diskSizeGB": 30,
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"caching": "ReadWrite",
"createOption": "FromImage",
"osType": "Linux"
},
"dataDisks": [
{
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS",
"diskEncryptionSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
}
},
"diskSizeGB": 1023,
"createOption": "Empty",
"lun": 0
},
{
"caching": "ReadWrite",
"managedDisk": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-managed-disk-name}",
"storageAccountType": "Standard_LRS",
"diskEncryptionSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
}
},
"diskSizeGB": 1023,
"createOption": "Attach",
"lun": 1
}
]
},
"vmId": "71aa3d5a-d73d-4970-9182-8580433b2865",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a vm with empty data disks.
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D2_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
},
"dataDisks": [
{
"diskSizeGB": 1023,
"createOption": "Empty",
"lun": 0
},
{
"diskSizeGB": 1023,
"createOption": "Empty",
"lun": 1
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DataDisk;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithEmptyDataDisks.json
*/
/**
* Sample code: Create a vm with empty data disks.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAVmWithEmptyDataDisks(com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS)))
.withDataDisks(Arrays.asList(
new DataDisk().withLun(0).withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023),
new DataDisk().withLun(1).withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023))))
.withOsProfile(new OSProfile()
.withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_with_empty_data_disks.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D2_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"dataDisks": [
{"createOption": "Empty", "diskSizeGB": 1023, "lun": 0},
{"createOption": "Empty", "diskSizeGB": 1023, "lun": 1},
],
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithEmptyDataDisks.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithEmptyDataDisks.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMWithEmptyDataDisks() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2V2),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("2016-Datacenter"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
Version: to.Ptr("latest"),
Offer: to.Ptr("WindowsServer"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
Name: to.Ptr("myVMosdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
DataDisks: []*armcompute.DataDisk{
{
DiskSizeGB: to.Ptr[int32](1023),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesEmpty),
Lun: to.Ptr[int32](0),
},
{
DiskSizeGB: to.Ptr[int32](1023),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesEmpty),
Lun: to.Ptr[int32](1),
},
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("2016-Datacenter"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("WindowsServer"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// },
// DataDisks: []*armcompute.DataDisk{
// {
// Caching: to.Ptr(armcompute.CachingTypesNone),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesEmpty),
// Lun: to.Ptr[int32](0),
// DiskSizeGB: to.Ptr[int32](1023),
// },
// {
// Caching: to.Ptr(armcompute.CachingTypesNone),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesEmpty),
// Lun: to.Ptr[int32](1),
// DiskSizeGB: to.Ptr[int32](1023),
// },
// },
// },
// VMID: to.Ptr("3906fef9-a1e5-4b83-a8a8-540858b41df0"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2V2),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Name: to.Ptr("myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithEmptyDataDisks.json
*/
async function createAVmWithEmptyDataDisks() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D2_v2" },
storageProfile: {
imageReference: {
sku: "2016-Datacenter",
publisher: "MicrosoftWindowsServer",
version: "latest",
offer: "WindowsServer",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Standard_LRS" },
name: "myVMosdisk",
createOption: "FromImage",
},
dataDisks: [
{ diskSizeGB: 1023, createOption: "Empty", lun: 0 },
{ diskSizeGB: 1023, createOption: "Empty", lun: 1 },
],
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": [
{
"caching": "None",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "Empty",
"lun": 0,
"diskSizeGB": 1023
},
{
"caching": "None",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "Empty",
"lun": 1,
"diskSizeGB": 1023
}
]
},
"vmId": "3906fef9-a1e5-4b83-a8a8-540858b41df0",
"hardwareProfile": {
"vmSize": "Standard_D2_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": [
{
"caching": "None",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "Empty",
"lun": 0,
"diskSizeGB": 1023,
"toBeDetached": false
},
{
"caching": "None",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "Empty",
"lun": 1,
"diskSizeGB": 1023,
"toBeDetached": false
}
]
},
"vmId": "3906fef9-a1e5-4b83-a8a8-540858b41df0",
"hardwareProfile": {
"vmSize": "Standard_D2_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a VM with encryption identity
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myIdentity": {}
}
},
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"securityProfile": {
"encryptionIdentity": {
"userAssignedIdentityResourceId": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myIdentity"
}
},
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "2019-Datacenter",
"version": "latest"
},
"osDisk": {
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "StandardSSD_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.EncryptionIdentity;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.ResourceIdentityType;
import com.azure.resourcemanager.compute.models.SecurityProfile;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineIdentity;
import com.azure.resourcemanager.compute.models.VirtualMachineIdentityUserAssignedIdentities;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithEncryptionIdentity.json
*/
/**
* Sample code: Create a VM with encryption identity.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAVMWithEncryptionIdentity(com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM", new VirtualMachineInner()
.withLocation("westus")
.withIdentity(new VirtualMachineIdentity().withType(ResourceIdentityType.USER_ASSIGNED)
.withUserAssignedIdentities(mapOf(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myIdentity",
new VirtualMachineIdentityUserAssignedIdentities())))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2019-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withEncryptionIdentity(new EncryptionIdentity().withUserAssignedIdentityResourceId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myIdentity"))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_with_encryption_identity.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myIdentity": {}
},
},
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D2s_v3"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"securityProfile": {
"encryptionIdentity": {
"userAssignedIdentityResourceId": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myIdentity"
}
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2019-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadOnly",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "StandardSSD_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithEncryptionIdentity.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithEncryptionIdentity.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMWithEncryptionIdentity() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Identity: &armcompute.VirtualMachineIdentity{
Type: to.Ptr(armcompute.ResourceIdentityTypeUserAssigned),
UserAssignedIdentities: map[string]*armcompute.UserAssignedIdentitiesValue{
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myIdentity": {},
},
},
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2SV3),
},
SecurityProfile: &armcompute.SecurityProfile{
EncryptionIdentity: &armcompute.EncryptionIdentity{
UserAssignedIdentityResourceID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myIdentity"),
},
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
Publisher: to.Ptr("MicrosoftWindowsServer"),
Offer: to.Ptr("WindowsServer"),
SKU: to.Ptr("2019-Datacenter"),
Version: to.Ptr("latest"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadOnly),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardSSDLRS),
},
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
Name: to.Ptr("myVMosdisk"),
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Identity: &armcompute.VirtualMachineIdentity{
// Type: to.Ptr(armcompute.ResourceIdentityTypeUserAssigned),
// UserAssignedIdentities: map[string]*armcompute.UserAssignedIdentitiesValue{
// "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myIdentity": &armcompute.UserAssignedIdentitiesValue{
// },
// },
// },
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// Offer: to.Ptr("WindowsServer"),
// SKU: to.Ptr("2019-Datacenter"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadOnly),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardSSDLRS),
// },
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// SecurityProfile: &armcompute.SecurityProfile{
// EncryptionIdentity: &armcompute.EncryptionIdentity{
// UserAssignedIdentityResourceID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myIdentity"),
// },
// },
// VMID: to.Ptr("5c0d55a7-c407-4ed6-bf7d-ddb810267c85"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2SV3),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithEncryptionIdentity.json
*/
async function createAVMWithEncryptionIdentity() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
identity: {
type: "UserAssigned",
userAssignedIdentities: {
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myIdentity":
{},
},
},
hardwareProfile: { vmSize: "Standard_D2s_v3" },
securityProfile: {
encryptionIdentity: {
userAssignedIdentityResourceId:
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myIdentity",
},
},
storageProfile: {
imageReference: {
publisher: "MicrosoftWindowsServer",
offer: "WindowsServer",
sku: "2019-Datacenter",
version: "latest",
},
osDisk: {
caching: "ReadOnly",
managedDisk: { storageAccountType: "StandardSSD_LRS" },
createOption: "FromImage",
name: "myVMosdisk",
},
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"name": "myVM",
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myIdentity": {}
}
},
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "2019-Datacenter",
"version": "latest"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "StandardSSD_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"securityProfile": {
"encryptionIdentity": {
"userAssignedIdentityResourceId": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myIdentity"
}
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
{
"name": "myVM",
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myIdentity": {}
}
},
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "2019-Datacenter",
"version": "latest"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "StandardSSD_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"securityProfile": {
"encryptionIdentity": {
"userAssignedIdentityResourceId": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myIdentity"
}
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
Create a vm with ephemeral os disk provisioning in Cache disk using placement property.
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"plan": {
"publisher": "microsoft-ads",
"product": "windows-data-science-vm",
"name": "windows2016"
},
"properties": {
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "windows2016",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "windows-data-science-vm"
},
"osDisk": {
"caching": "ReadOnly",
"diffDiskSettings": {
"option": "Local",
"placement": "CacheDisk"
},
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiffDiskOptions;
import com.azure.resourcemanager.compute.models.DiffDiskPlacement;
import com.azure.resourcemanager.compute.models.DiffDiskSettings;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.Plan;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithADiffOsDiskUsingDiffDiskPlacementAsCacheDisk.json
*/
/**
* Sample code: Create a vm with ephemeral os disk provisioning in Cache disk using placement property.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAVmWithEphemeralOsDiskProvisioningInCacheDiskUsingPlacementProperty(
com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_DS1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withDiffDiskSettings(new DiffDiskSettings().withOption(DiffDiskOptions.LOCAL)
.withPlacement(DiffDiskPlacement.CACHE_DISK))
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile()
.withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_with_adiff_os_disk_using_diff_disk_placement_as_cache_disk.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"plan": {"name": "windows2016", "product": "windows-data-science-vm", "publisher": "microsoft-ads"},
"properties": {
"hardwareProfile": {"vmSize": "Standard_DS1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"offer": "windows-data-science-vm",
"publisher": "microsoft-ads",
"sku": "windows2016",
"version": "latest",
},
"osDisk": {
"caching": "ReadOnly",
"createOption": "FromImage",
"diffDiskSettings": {"option": "Local", "placement": "CacheDisk"},
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithADiffOsDiskUsingDiffDiskPlacementAsCacheDisk.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithADiffOsDiskUsingDiffDiskPlacementAsCacheDisk.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMWithEphemeralOSDiskProvisioningInCacheDiskUsingPlacementProperty() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Plan: &armcompute.Plan{
Publisher: to.Ptr("microsoft-ads"),
Product: to.Ptr("windows-data-science-vm"),
Name: to.Ptr("windows2016"),
},
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("windows2016"),
Publisher: to.Ptr("microsoft-ads"),
Version: to.Ptr("latest"),
Offer: to.Ptr("windows-data-science-vm"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadOnly),
DiffDiskSettings: &armcompute.DiffDiskSettings{
Option: to.Ptr(armcompute.DiffDiskOptionsLocal),
Placement: to.Ptr(armcompute.DiffDiskPlacementCacheDisk),
},
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
Name: to.Ptr("myVMosdisk"),
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("standard-data-science-vm"),
// Publisher: to.Ptr("microsoft-ads"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("standard-data-science-vm"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadOnly),
// DiffDiskSettings: &armcompute.DiffDiskSettings{
// Option: to.Ptr(armcompute.DiffDiskOptionsLocal),
// Placement: to.Ptr(armcompute.DiffDiskPlacementCacheDisk),
// },
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// VMID: to.Ptr("5c0d55a7-c407-4ed6-bf7d-ddb810267c85"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Plan: &armcompute.Plan{
// Publisher: to.Ptr("microsoft-ads"),
// Product: to.Ptr("standard-data-science-vm"),
// Name: to.Ptr("standard-data-science-vm"),
// },
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithADiffOsDiskUsingDiffDiskPlacementAsCacheDisk.json
*/
async function createAVmWithEphemeralOsDiskProvisioningInCacheDiskUsingPlacementProperty() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
plan: { publisher: "microsoft-ads", product: "windows-data-science-vm", name: "windows2016" },
hardwareProfile: { vmSize: "Standard_DS1_v2" },
storageProfile: {
imageReference: {
sku: "windows2016",
publisher: "microsoft-ads",
version: "latest",
offer: "windows-data-science-vm",
},
osDisk: {
caching: "ReadOnly",
diffDiskSettings: { option: "Local", placement: "CacheDisk" },
managedDisk: { storageAccountType: "Standard_LRS" },
createOption: "FromImage",
name: "myVMosdisk",
},
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "standard-data-science-vm",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "standard-data-science-vm"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadOnly",
"diffDiskSettings": {
"option": "Local",
"placement": "CacheDisk"
},
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"plan": {
"publisher": "microsoft-ads",
"product": "standard-data-science-vm",
"name": "standard-data-science-vm"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "standard-data-science-vm",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "standard-data-science-vm"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadOnly",
"diffDiskSettings": {
"option": "Local",
"placement": "CacheDisk"
},
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"plan": {
"publisher": "microsoft-ads",
"product": "standard-data-science-vm",
"name": "standard-data-science-vm"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
Create a vm with ephemeral os disk provisioning in Nvme disk using placement property.
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"plan": {
"publisher": "microsoft-ads",
"product": "windows-data-science-vm",
"name": "windows2016"
},
"properties": {
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "windows2016",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "windows-data-science-vm"
},
"osDisk": {
"caching": "ReadOnly",
"diffDiskSettings": {
"option": "Local",
"placement": "NvmeDisk"
},
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiffDiskOptions;
import com.azure.resourcemanager.compute.models.DiffDiskPlacement;
import com.azure.resourcemanager.compute.models.DiffDiskSettings;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.Plan;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithADiffOsDiskUsingDiffDiskPlacementAsNvmeDisk.json
*/
/**
* Sample code: Create a vm with ephemeral os disk provisioning in Nvme disk using placement property.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAVmWithEphemeralOsDiskProvisioningInNvmeDiskUsingPlacementProperty(
com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_DS1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withDiffDiskSettings(new DiffDiskSettings().withOption(DiffDiskOptions.LOCAL)
.withPlacement(DiffDiskPlacement.NVME_DISK))
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile()
.withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_with_adiff_os_disk_using_diff_disk_placement_as_nvme_disk.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"plan": {"name": "windows2016", "product": "windows-data-science-vm", "publisher": "microsoft-ads"},
"properties": {
"hardwareProfile": {"vmSize": "Standard_DS1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"offer": "windows-data-science-vm",
"publisher": "microsoft-ads",
"sku": "windows2016",
"version": "latest",
},
"osDisk": {
"caching": "ReadOnly",
"createOption": "FromImage",
"diffDiskSettings": {"option": "Local", "placement": "NvmeDisk"},
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithADiffOsDiskUsingDiffDiskPlacementAsNvmeDisk.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithADiffOsDiskUsingDiffDiskPlacementAsNvmeDisk.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMWithEphemeralOSDiskProvisioningInNvmeDiskUsingPlacementProperty() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Plan: &armcompute.Plan{
Publisher: to.Ptr("microsoft-ads"),
Product: to.Ptr("windows-data-science-vm"),
Name: to.Ptr("windows2016"),
},
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("windows2016"),
Publisher: to.Ptr("microsoft-ads"),
Version: to.Ptr("latest"),
Offer: to.Ptr("windows-data-science-vm"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadOnly),
DiffDiskSettings: &armcompute.DiffDiskSettings{
Option: to.Ptr(armcompute.DiffDiskOptionsLocal),
Placement: to.Ptr(armcompute.DiffDiskPlacementNvmeDisk),
},
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
Name: to.Ptr("myVMosdisk"),
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("standard-data-science-vm"),
// Publisher: to.Ptr("microsoft-ads"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("standard-data-science-vm"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadOnly),
// DiffDiskSettings: &armcompute.DiffDiskSettings{
// Option: to.Ptr(armcompute.DiffDiskOptionsLocal),
// Placement: to.Ptr(armcompute.DiffDiskPlacementNvmeDisk),
// },
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// VMID: to.Ptr("5c0d55a7-c407-4ed6-bf7d-ddb810267c85"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Plan: &armcompute.Plan{
// Publisher: to.Ptr("microsoft-ads"),
// Product: to.Ptr("standard-data-science-vm"),
// Name: to.Ptr("standard-data-science-vm"),
// },
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithADiffOsDiskUsingDiffDiskPlacementAsNvmeDisk.json
*/
async function createAVmWithEphemeralOsDiskProvisioningInNvmeDiskUsingPlacementProperty() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
plan: { publisher: "microsoft-ads", product: "windows-data-science-vm", name: "windows2016" },
hardwareProfile: { vmSize: "Standard_DS1_v2" },
storageProfile: {
imageReference: {
sku: "windows2016",
publisher: "microsoft-ads",
version: "latest",
offer: "windows-data-science-vm",
},
osDisk: {
caching: "ReadOnly",
diffDiskSettings: { option: "Local", placement: "NvmeDisk" },
managedDisk: { storageAccountType: "Standard_LRS" },
createOption: "FromImage",
name: "myVMosdisk",
},
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "standard-data-science-vm",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "standard-data-science-vm"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadOnly",
"diffDiskSettings": {
"option": "Local",
"placement": "NvmeDisk"
},
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"plan": {
"publisher": "microsoft-ads",
"product": "standard-data-science-vm",
"name": "standard-data-science-vm"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "standard-data-science-vm",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "standard-data-science-vm"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadOnly",
"diffDiskSettings": {
"option": "Local",
"placement": "NvmeDisk"
},
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"plan": {
"publisher": "microsoft-ads",
"product": "standard-data-science-vm",
"name": "standard-data-science-vm"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
Create a vm with ephemeral os disk provisioning in Resource disk using placement property.
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"plan": {
"publisher": "microsoft-ads",
"product": "windows-data-science-vm",
"name": "windows2016"
},
"properties": {
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "windows2016",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "windows-data-science-vm"
},
"osDisk": {
"caching": "ReadOnly",
"diffDiskSettings": {
"option": "Local",
"placement": "ResourceDisk"
},
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiffDiskOptions;
import com.azure.resourcemanager.compute.models.DiffDiskPlacement;
import com.azure.resourcemanager.compute.models.DiffDiskSettings;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.Plan;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithADiffOsDiskUsingDiffDiskPlacementAsResourceDisk.json
*/
/**
* Sample code: Create a vm with ephemeral os disk provisioning in Resource disk using placement property.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAVmWithEphemeralOsDiskProvisioningInResourceDiskUsingPlacementProperty(
com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_DS1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withDiffDiskSettings(new DiffDiskSettings().withOption(DiffDiskOptions.LOCAL)
.withPlacement(DiffDiskPlacement.RESOURCE_DISK))
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile()
.withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_with_adiff_os_disk_using_diff_disk_placement_as_resource_disk.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"plan": {"name": "windows2016", "product": "windows-data-science-vm", "publisher": "microsoft-ads"},
"properties": {
"hardwareProfile": {"vmSize": "Standard_DS1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"offer": "windows-data-science-vm",
"publisher": "microsoft-ads",
"sku": "windows2016",
"version": "latest",
},
"osDisk": {
"caching": "ReadOnly",
"createOption": "FromImage",
"diffDiskSettings": {"option": "Local", "placement": "ResourceDisk"},
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithADiffOsDiskUsingDiffDiskPlacementAsResourceDisk.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithADiffOsDiskUsingDiffDiskPlacementAsResourceDisk.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMWithEphemeralOSDiskProvisioningInResourceDiskUsingPlacementProperty() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Plan: &armcompute.Plan{
Publisher: to.Ptr("microsoft-ads"),
Product: to.Ptr("windows-data-science-vm"),
Name: to.Ptr("windows2016"),
},
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("windows2016"),
Publisher: to.Ptr("microsoft-ads"),
Version: to.Ptr("latest"),
Offer: to.Ptr("windows-data-science-vm"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadOnly),
DiffDiskSettings: &armcompute.DiffDiskSettings{
Option: to.Ptr(armcompute.DiffDiskOptionsLocal),
Placement: to.Ptr(armcompute.DiffDiskPlacementResourceDisk),
},
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
Name: to.Ptr("myVMosdisk"),
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("standard-data-science-vm"),
// Publisher: to.Ptr("microsoft-ads"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("standard-data-science-vm"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadOnly),
// DiffDiskSettings: &armcompute.DiffDiskSettings{
// Option: to.Ptr(armcompute.DiffDiskOptionsLocal),
// Placement: to.Ptr(armcompute.DiffDiskPlacementResourceDisk),
// },
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// VMID: to.Ptr("5c0d55a7-c407-4ed6-bf7d-ddb810267c85"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Plan: &armcompute.Plan{
// Publisher: to.Ptr("microsoft-ads"),
// Product: to.Ptr("standard-data-science-vm"),
// Name: to.Ptr("standard-data-science-vm"),
// },
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithADiffOsDiskUsingDiffDiskPlacementAsResourceDisk.json
*/
async function createAVmWithEphemeralOsDiskProvisioningInResourceDiskUsingPlacementProperty() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
plan: { publisher: "microsoft-ads", product: "windows-data-science-vm", name: "windows2016" },
hardwareProfile: { vmSize: "Standard_DS1_v2" },
storageProfile: {
imageReference: {
sku: "windows2016",
publisher: "microsoft-ads",
version: "latest",
offer: "windows-data-science-vm",
},
osDisk: {
caching: "ReadOnly",
diffDiskSettings: { option: "Local", placement: "ResourceDisk" },
managedDisk: { storageAccountType: "Standard_LRS" },
createOption: "FromImage",
name: "myVMosdisk",
},
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "standard-data-science-vm",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "standard-data-science-vm"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadOnly",
"diffDiskSettings": {
"option": "Local",
"placement": "ResourceDisk"
},
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"plan": {
"publisher": "microsoft-ads",
"product": "standard-data-science-vm",
"name": "standard-data-science-vm"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "standard-data-science-vm",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "standard-data-science-vm"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadOnly",
"diffDiskSettings": {
"option": "Local",
"placement": "ResourceDisk"
},
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"plan": {
"publisher": "microsoft-ads",
"product": "standard-data-science-vm",
"name": "standard-data-science-vm"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
Create a vm with ephemeral os disk.
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"plan": {
"publisher": "microsoft-ads",
"product": "windows-data-science-vm",
"name": "windows2016"
},
"properties": {
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "windows2016",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "windows-data-science-vm"
},
"osDisk": {
"caching": "ReadOnly",
"diffDiskSettings": {
"option": "Local"
},
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiffDiskOptions;
import com.azure.resourcemanager.compute.models.DiffDiskSettings;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.Plan;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithADiffOsDisk.json
*/
/**
* Sample code: Create a vm with ephemeral os disk.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAVmWithEphemeralOsDisk(com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_DS1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withDiffDiskSettings(new DiffDiskSettings().withOption(DiffDiskOptions.LOCAL))
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile()
.withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_with_adiff_os_disk.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"plan": {"name": "windows2016", "product": "windows-data-science-vm", "publisher": "microsoft-ads"},
"properties": {
"hardwareProfile": {"vmSize": "Standard_DS1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"offer": "windows-data-science-vm",
"publisher": "microsoft-ads",
"sku": "windows2016",
"version": "latest",
},
"osDisk": {
"caching": "ReadOnly",
"createOption": "FromImage",
"diffDiskSettings": {"option": "Local"},
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithADiffOsDisk.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithADiffOsDisk.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMWithEphemeralOSDisk() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Plan: &armcompute.Plan{
Publisher: to.Ptr("microsoft-ads"),
Product: to.Ptr("windows-data-science-vm"),
Name: to.Ptr("windows2016"),
},
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("windows2016"),
Publisher: to.Ptr("microsoft-ads"),
Version: to.Ptr("latest"),
Offer: to.Ptr("windows-data-science-vm"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadOnly),
DiffDiskSettings: &armcompute.DiffDiskSettings{
Option: to.Ptr(armcompute.DiffDiskOptionsLocal),
},
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
Name: to.Ptr("myVMosdisk"),
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("standard-data-science-vm"),
// Publisher: to.Ptr("microsoft-ads"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("standard-data-science-vm"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadOnly),
// DiffDiskSettings: &armcompute.DiffDiskSettings{
// Option: to.Ptr(armcompute.DiffDiskOptionsLocal),
// },
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// VMID: to.Ptr("5c0d55a7-c407-4ed6-bf7d-ddb810267c85"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Plan: &armcompute.Plan{
// Publisher: to.Ptr("microsoft-ads"),
// Product: to.Ptr("standard-data-science-vm"),
// Name: to.Ptr("standard-data-science-vm"),
// },
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithADiffOsDisk.json
*/
async function createAVmWithEphemeralOsDisk() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
plan: { publisher: "microsoft-ads", product: "windows-data-science-vm", name: "windows2016" },
hardwareProfile: { vmSize: "Standard_DS1_v2" },
storageProfile: {
imageReference: {
sku: "windows2016",
publisher: "microsoft-ads",
version: "latest",
offer: "windows-data-science-vm",
},
osDisk: {
caching: "ReadOnly",
diffDiskSettings: { option: "Local" },
managedDisk: { storageAccountType: "Standard_LRS" },
createOption: "FromImage",
name: "myVMosdisk",
},
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "standard-data-science-vm",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "standard-data-science-vm"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadOnly",
"diffDiskSettings": {
"option": "Local"
},
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"plan": {
"publisher": "microsoft-ads",
"product": "standard-data-science-vm",
"name": "standard-data-science-vm"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "standard-data-science-vm",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "standard-data-science-vm"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadOnly",
"diffDiskSettings": {
"option": "Local"
},
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"plan": {
"publisher": "microsoft-ads",
"product": "standard-data-science-vm",
"name": "standard-data-science-vm"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
Create a VM with FIPS 140-3 Enabled
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/{vm-name}?api-version=2026-04-01
{
"location": "eastus2euap",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"additionalCapabilities": {
"enableFips1403Encryption": true
},
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "2019-Datacenter",
"version": "latest"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "vmOSdisk",
"createOption": "FromImage"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "{vm-name}",
"adminPassword": "{your-password}"
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://{existing-storage-account-name}.blob.core.windows.net",
"enabled": true
}
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.AdditionalCapabilities;
import com.azure.resourcemanager.compute.models.BootDiagnostics;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiagnosticsProfile;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithFips1403Enabled.json
*/
/**
* Sample code: Create a VM with FIPS 140-3 Enabled.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAVMWithFIPS1403Enabled(com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "{vm-name}",
new VirtualMachineInner().withLocation("eastus2euap")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2019-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("vmOSdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withAdditionalCapabilities(new AdditionalCapabilities().withEnableFips1403Encryption(true))
.withOsProfile(new OSProfile().withComputerName("{vm-name}").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net"))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_with_fips1403_enabled.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="{vm-name}",
parameters={
"location": "eastus2euap",
"properties": {
"additionalCapabilities": {"enableFips1403Encryption": True},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": True,
"storageUri": "http://{existing-storage-account-name}.blob.core.windows.net",
}
},
"hardwareProfile": {"vmSize": "Standard_D2s_v3"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "{vm-name}",
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2019-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "vmOSdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithFips1403Enabled.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithFips1403Enabled.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMWithFips1403Enabled() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "{vm-name}", armcompute.VirtualMachine{
Location: to.Ptr("eastus2euap"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2SV3),
},
AdditionalCapabilities: &armcompute.AdditionalCapabilities{
EnableFips1403Encryption: to.Ptr(true),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
Publisher: to.Ptr("MicrosoftWindowsServer"),
Offer: to.Ptr("WindowsServer"),
SKU: to.Ptr("2019-Datacenter"),
Version: to.Ptr("latest"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
Name: to.Ptr("vmOSdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("{vm-name}"),
AdminPassword: to.Ptr("{your-password}"),
},
DiagnosticsProfile: &armcompute.DiagnosticsProfile{
BootDiagnostics: &armcompute.BootDiagnostics{
StorageURI: to.Ptr("http://{existing-storage-account-name}.blob.core.windows.net"),
Enabled: to.Ptr(true),
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/{vm-name}"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("{vm-name}"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// Offer: to.Ptr("WindowsServer"),
// SKU: to.Ptr("2019-Datacenter"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("vmOSdisk"),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// DiagnosticsProfile: &armcompute.DiagnosticsProfile{
// BootDiagnostics: &armcompute.BootDiagnostics{
// StorageURI: to.Ptr("http://nsgdiagnostic.blob.core.windows.net"),
// Enabled: to.Ptr(true),
// },
// },
// VMID: to.Ptr("676420ba-7a24-4bfe-80bd-9c841ee184fa"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2SV3),
// },
// AdditionalCapabilities: &armcompute.AdditionalCapabilities{
// EnableFips1403Encryption: to.Ptr(true),
// },
// ProvisioningState: to.Ptr("Updating"),
// },
// Name: to.Ptr("{vm-name}"),
// Location: to.Ptr("eastus2euap"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithFips1403Enabled.json
*/
async function createAVMWithFips1403Enabled() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "{vm-name}", {
location: "eastus2euap",
hardwareProfile: { vmSize: "Standard_D2s_v3" },
additionalCapabilities: { enableFips1403Encryption: true },
storageProfile: {
imageReference: {
publisher: "MicrosoftWindowsServer",
offer: "WindowsServer",
sku: "2019-Datacenter",
version: "latest",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Standard_LRS" },
name: "vmOSdisk",
createOption: "FromImage",
},
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminUsername: "{your-username}",
computerName: "{vm-name}",
adminPassword: "{your-password}",
},
diagnosticsProfile: {
bootDiagnostics: {
storageUri: "http://{existing-storage-account-name}.blob.core.windows.net",
enabled: true,
},
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/{vm-name}",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "{vm-name}",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "2019-Datacenter",
"version": "latest"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "vmOSdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://nsgdiagnostic.blob.core.windows.net",
"enabled": true
}
},
"vmId": "676420ba-7a24-4bfe-80bd-9c841ee184fa",
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"additionalCapabilities": {
"enableFips1403Encryption": true
},
"provisioningState": "Updating"
},
"name": "{vm-name}",
"location": "eastus2euap"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/{vm-name}",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "{vm-name}",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "2019-Datacenter",
"version": "latest"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "vmOSdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://nsgdiagnostic.blob.core.windows.net",
"enabled": true
}
},
"vmId": "676420ba-7a24-4bfe-80bd-9c841ee184fa",
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"additionalCapabilities": {
"enableFips1403Encryption": true
},
"provisioningState": "Creating"
},
"name": "{vm-name}",
"location": "eastus2euap"
}
Create a VM with HibernationEnabled
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/{vm-name}?api-version=2026-04-01
{
"location": "eastus2euap",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"additionalCapabilities": {
"hibernationEnabled": true
},
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "2019-Datacenter",
"version": "latest"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "vmOSdisk",
"createOption": "FromImage"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "{vm-name}",
"adminPassword": "{your-password}"
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://{existing-storage-account-name}.blob.core.windows.net",
"enabled": true
}
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.AdditionalCapabilities;
import com.azure.resourcemanager.compute.models.BootDiagnostics;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiagnosticsProfile;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithHibernationEnabled.json
*/
/**
* Sample code: Create a VM with HibernationEnabled.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAVMWithHibernationEnabled(com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "{vm-name}",
new VirtualMachineInner().withLocation("eastus2euap")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2019-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("vmOSdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withAdditionalCapabilities(new AdditionalCapabilities().withHibernationEnabled(true))
.withOsProfile(new OSProfile().withComputerName("{vm-name}").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net"))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_with_hibernation_enabled.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="{vm-name}",
parameters={
"location": "eastus2euap",
"properties": {
"additionalCapabilities": {"hibernationEnabled": True},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": True,
"storageUri": "http://{existing-storage-account-name}.blob.core.windows.net",
}
},
"hardwareProfile": {"vmSize": "Standard_D2s_v3"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "{vm-name}",
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2019-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "vmOSdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithHibernationEnabled.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithHibernationEnabled.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMWithHibernationEnabled() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "{vm-name}", armcompute.VirtualMachine{
Location: to.Ptr("eastus2euap"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2SV3),
},
AdditionalCapabilities: &armcompute.AdditionalCapabilities{
HibernationEnabled: to.Ptr(true),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
Publisher: to.Ptr("MicrosoftWindowsServer"),
Offer: to.Ptr("WindowsServer"),
SKU: to.Ptr("2019-Datacenter"),
Version: to.Ptr("latest"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
Name: to.Ptr("vmOSdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("{vm-name}"),
AdminPassword: to.Ptr("{your-password}"),
},
DiagnosticsProfile: &armcompute.DiagnosticsProfile{
BootDiagnostics: &armcompute.BootDiagnostics{
StorageURI: to.Ptr("http://{existing-storage-account-name}.blob.core.windows.net"),
Enabled: to.Ptr(true),
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/{vm-name}"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("{vm-name}"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// Offer: to.Ptr("WindowsServer"),
// SKU: to.Ptr("2019-Datacenter"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("vmOSdisk"),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// DiagnosticsProfile: &armcompute.DiagnosticsProfile{
// BootDiagnostics: &armcompute.BootDiagnostics{
// StorageURI: to.Ptr("http://nsgdiagnostic.blob.core.windows.net"),
// Enabled: to.Ptr(true),
// },
// },
// VMID: to.Ptr("676420ba-7a24-4bfe-80bd-9c841ee184fa"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2SV3),
// },
// AdditionalCapabilities: &armcompute.AdditionalCapabilities{
// HibernationEnabled: to.Ptr(true),
// },
// ProvisioningState: to.Ptr("Updating"),
// },
// Name: to.Ptr("{vm-name}"),
// Location: to.Ptr("eastus2euap"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithHibernationEnabled.json
*/
async function createAVMWithHibernationEnabled() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "{vm-name}", {
location: "eastus2euap",
hardwareProfile: { vmSize: "Standard_D2s_v3" },
additionalCapabilities: { hibernationEnabled: true },
storageProfile: {
imageReference: {
publisher: "MicrosoftWindowsServer",
offer: "WindowsServer",
sku: "2019-Datacenter",
version: "latest",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Standard_LRS" },
name: "vmOSdisk",
createOption: "FromImage",
},
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminUsername: "{your-username}",
computerName: "{vm-name}",
adminPassword: "{your-password}",
},
diagnosticsProfile: {
bootDiagnostics: {
storageUri: "http://{existing-storage-account-name}.blob.core.windows.net",
enabled: true,
},
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/{vm-name}",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "{vm-name}",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "2019-Datacenter",
"version": "latest"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "vmOSdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://nsgdiagnostic.blob.core.windows.net",
"enabled": true
}
},
"vmId": "676420ba-7a24-4bfe-80bd-9c841ee184fa",
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"additionalCapabilities": {
"hibernationEnabled": true
},
"provisioningState": "Updating"
},
"name": "{vm-name}",
"location": "eastus2euap"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/{vm-name}",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "{vm-name}",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "2019-Datacenter",
"version": "latest"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "vmOSdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://nsgdiagnostic.blob.core.windows.net",
"enabled": true
}
},
"vmId": "676420ba-7a24-4bfe-80bd-9c841ee184fa",
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"additionalCapabilities": {
"hibernationEnabled": true
},
"provisioningState": "Creating"
},
"name": "{vm-name}",
"location": "eastus2euap"
}
Create a vm with Host Encryption using encryptionAtHost property.
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"plan": {
"publisher": "microsoft-ads",
"product": "windows-data-science-vm",
"name": "windows2016"
},
"properties": {
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"securityProfile": {
"encryptionAtHost": true
},
"storageProfile": {
"imageReference": {
"sku": "windows2016",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "windows-data-science-vm"
},
"osDisk": {
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.Plan;
import com.azure.resourcemanager.compute.models.SecurityProfile;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithEncryptionAtHost.json
*/
/**
* Sample code: Create a vm with Host Encryption using encryptionAtHost property.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAVmWithHostEncryptionUsingEncryptionAtHostProperty(
com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_DS1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile()
.withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile().withEncryptionAtHost(true)),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_with_encryption_at_host.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"plan": {"name": "windows2016", "product": "windows-data-science-vm", "publisher": "microsoft-ads"},
"properties": {
"hardwareProfile": {"vmSize": "Standard_DS1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"securityProfile": {"encryptionAtHost": True},
"storageProfile": {
"imageReference": {
"offer": "windows-data-science-vm",
"publisher": "microsoft-ads",
"sku": "windows2016",
"version": "latest",
},
"osDisk": {
"caching": "ReadOnly",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithEncryptionAtHost.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithEncryptionAtHost.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMWithHostEncryptionUsingEncryptionAtHostProperty() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Plan: &armcompute.Plan{
Publisher: to.Ptr("microsoft-ads"),
Product: to.Ptr("windows-data-science-vm"),
Name: to.Ptr("windows2016"),
},
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
},
SecurityProfile: &armcompute.SecurityProfile{
EncryptionAtHost: to.Ptr(true),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("windows2016"),
Publisher: to.Ptr("microsoft-ads"),
Version: to.Ptr("latest"),
Offer: to.Ptr("windows-data-science-vm"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadOnly),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
Name: to.Ptr("myVMosdisk"),
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("standard-data-science-vm"),
// Publisher: to.Ptr("microsoft-ads"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("standard-data-science-vm"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadOnly),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// SecurityProfile: &armcompute.SecurityProfile{
// EncryptionAtHost: to.Ptr(true),
// },
// VMID: to.Ptr("5c0d55a7-c407-4ed6-bf7d-ddb810267c85"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Plan: &armcompute.Plan{
// Publisher: to.Ptr("microsoft-ads"),
// Product: to.Ptr("standard-data-science-vm"),
// Name: to.Ptr("standard-data-science-vm"),
// },
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithEncryptionAtHost.json
*/
async function createAVmWithHostEncryptionUsingEncryptionAtHostProperty() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
plan: { publisher: "microsoft-ads", product: "windows-data-science-vm", name: "windows2016" },
hardwareProfile: { vmSize: "Standard_DS1_v2" },
securityProfile: { encryptionAtHost: true },
storageProfile: {
imageReference: {
sku: "windows2016",
publisher: "microsoft-ads",
version: "latest",
offer: "windows-data-science-vm",
},
osDisk: {
caching: "ReadOnly",
managedDisk: { storageAccountType: "Standard_LRS" },
createOption: "FromImage",
name: "myVMosdisk",
},
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "standard-data-science-vm",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "standard-data-science-vm"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"securityProfile": {
"encryptionAtHost": true
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"plan": {
"publisher": "microsoft-ads",
"product": "standard-data-science-vm",
"name": "standard-data-science-vm"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "standard-data-science-vm",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "standard-data-science-vm"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"securityProfile": {
"encryptionAtHost": true
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"plan": {
"publisher": "microsoft-ads",
"product": "standard-data-science-vm",
"name": "standard-data-science-vm"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
Create a vm with managed boot diagnostics.
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true
}
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.BootDiagnostics;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiagnosticsProfile;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithManagedBootDiagnostics.json
*/
/**
* Sample code: Create a vm with managed boot diagnostics.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAVmWithManagedBootDiagnostics(com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile()
.withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(
new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics().withEnabled(true))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_with_managed_boot_diagnostics.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"diagnosticsProfile": {"bootDiagnostics": {"enabled": True}},
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithManagedBootDiagnostics.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithManagedBootDiagnostics.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMWithManagedBootDiagnostics() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("2016-Datacenter"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
Version: to.Ptr("latest"),
Offer: to.Ptr("WindowsServer"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
Name: to.Ptr("myVMosdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
DiagnosticsProfile: &armcompute.DiagnosticsProfile{
BootDiagnostics: &armcompute.BootDiagnostics{
Enabled: to.Ptr(true),
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("2016-Datacenter"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("WindowsServer"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// DiagnosticsProfile: &armcompute.DiagnosticsProfile{
// BootDiagnostics: &armcompute.BootDiagnostics{
// Enabled: to.Ptr(true),
// },
// },
// VMID: to.Ptr("676420ba-7a24-4bfe-80bd-9c841ee184fa"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Name: to.Ptr("myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithManagedBootDiagnostics.json
*/
async function createAVmWithManagedBootDiagnostics() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D1_v2" },
storageProfile: {
imageReference: {
sku: "2016-Datacenter",
publisher: "MicrosoftWindowsServer",
version: "latest",
offer: "WindowsServer",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Standard_LRS" },
name: "myVMosdisk",
createOption: "FromImage",
},
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
diagnosticsProfile: { bootDiagnostics: { enabled: true } },
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true
}
},
"vmId": "676420ba-7a24-4bfe-80bd-9c841ee184fa",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true
}
},
"vmId": "676420ba-7a24-4bfe-80bd-9c841ee184fa",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a VM with network interface configuration
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"networkProfile": {
"networkApiVersion": "2020-11-01",
"networkInterfaceConfigurations": [
{
"name": "{nic-config-name}",
"tags": {
"nicTag": "tag"
},
"properties": {
"primary": true,
"deleteOption": "Delete",
"ipConfigurations": [
{
"name": "{ip-config-name}",
"properties": {
"primary": true,
"publicIPAddressConfiguration": {
"name": "{publicIP-config-name}",
"tags": {
"pipTag": "tag"
},
"sku": {
"name": "Basic",
"tier": "Global"
},
"properties": {
"deleteOption": "Detach",
"publicIPAllocationMethod": "Static"
}
}
}
}
]
}
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DeleteOptions;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkApiVersion;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.PublicIpAddressSku;
import com.azure.resourcemanager.compute.models.PublicIpAddressSkuName;
import com.azure.resourcemanager.compute.models.PublicIpAddressSkuTier;
import com.azure.resourcemanager.compute.models.PublicIpAllocationMethod;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineNetworkInterfaceConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineNetworkInterfaceIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachinePublicIpAddressConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithNetworkInterfaceConfiguration.json
*/
/**
* Sample code: Create a VM with network interface configuration.
*
* @param manager Entry point to ComputeManager.
*/
public static void
createAVMWithNetworkInterfaceConfiguration(com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkApiVersion(NetworkApiVersion.TWO_ZERO_TWO_ZERO_ONE_ONE_ZERO_ONE)
.withNetworkInterfaceConfigurations(
Arrays.asList(new VirtualMachineNetworkInterfaceConfiguration()
.withName("{nic-config-name}").withTags(mapOf("nicTag", "tag")).withPrimary(true)
.withDeleteOption(DeleteOptions.DELETE)
.withIpConfigurations(Arrays.asList(new VirtualMachineNetworkInterfaceIpConfiguration()
.withName("{ip-config-name}").withPrimary(true)
.withPublicIpAddressConfiguration(new VirtualMachinePublicIpAddressConfiguration()
.withName("{publicIP-config-name}")
.withSku(new PublicIpAddressSku().withName(PublicIpAddressSkuName.BASIC)
.withTier(PublicIpAddressSkuTier.GLOBAL))
.withTags(mapOf("pipTag", "tag")).withDeleteOption(DeleteOptions.DETACH)
.withPublicIpAllocationMethod(PublicIpAllocationMethod.STATIC))))))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_with_network_interface_configuration.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkApiVersion": "2020-11-01",
"networkInterfaceConfigurations": [
{
"name": "{nic-config-name}",
"properties": {
"deleteOption": "Delete",
"ipConfigurations": [
{
"name": "{ip-config-name}",
"properties": {
"primary": True,
"publicIPAddressConfiguration": {
"name": "{publicIP-config-name}",
"properties": {
"deleteOption": "Detach",
"publicIPAllocationMethod": "Static",
},
"sku": {"name": "Basic", "tier": "Global"},
"tags": {"pipTag": "tag"},
},
},
}
],
"primary": True,
},
"tags": {"nicTag": "tag"},
}
],
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithNetworkInterfaceConfiguration.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithNetworkInterfaceConfiguration.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMWithNetworkInterfaceConfiguration() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("2016-Datacenter"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
Version: to.Ptr("latest"),
Offer: to.Ptr("WindowsServer"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
Name: to.Ptr("myVMosdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkAPIVersion: to.Ptr(armcompute.NetworkAPIVersionTwoThousandTwenty1101),
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineNetworkInterfaceConfiguration{
{
Name: to.Ptr("{nic-config-name}"),
Tags: map[string]*string{
"nicTag": to.Ptr("tag"),
},
Properties: &armcompute.VirtualMachineNetworkInterfaceConfigurationProperties{
Primary: to.Ptr(true),
DeleteOption: to.Ptr(armcompute.DeleteOptionsDelete),
IPConfigurations: []*armcompute.VirtualMachineNetworkInterfaceIPConfiguration{
{
Name: to.Ptr("{ip-config-name}"),
Properties: &armcompute.VirtualMachineNetworkInterfaceIPConfigurationProperties{
Primary: to.Ptr(true),
PublicIPAddressConfiguration: &armcompute.VirtualMachinePublicIPAddressConfiguration{
Name: to.Ptr("{publicIP-config-name}"),
Tags: map[string]*string{
"pipTag": to.Ptr("tag"),
},
SKU: &armcompute.PublicIPAddressSKU{
Name: to.Ptr(armcompute.PublicIPAddressSKUNameBasic),
Tier: to.Ptr(armcompute.PublicIPAddressSKUTierGlobal),
},
Properties: &armcompute.VirtualMachinePublicIPAddressConfigurationProperties{
DeleteOption: to.Ptr(armcompute.DeleteOptionsDetach),
PublicIPAllocationMethod: to.Ptr(armcompute.PublicIPAllocationMethodStatic),
},
},
},
},
},
},
},
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/toBeCreatedNetworkInterface"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("2016-Datacenter"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("WindowsServer"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// VMID: to.Ptr("b7a098cc-b0b8-46e8-a205-62f301a62a8f"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Name: to.Ptr("myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithNetworkInterfaceConfiguration.json
*/
async function createAVMWithNetworkInterfaceConfiguration() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D1_v2" },
storageProfile: {
imageReference: {
sku: "2016-Datacenter",
publisher: "MicrosoftWindowsServer",
version: "latest",
offer: "WindowsServer",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Standard_LRS" },
name: "myVMosdisk",
createOption: "FromImage",
},
},
networkProfile: {
networkApiVersion: "2020-11-01",
networkInterfaceConfigurations: [
{
name: "{nic-config-name}",
tags: { nicTag: "tag" },
primary: true,
deleteOption: "Delete",
ipConfigurations: [
{
name: "{ip-config-name}",
primary: true,
publicIPAddressConfiguration: {
name: "{publicIP-config-name}",
tags: { pipTag: "tag" },
sku: { name: "Basic", tier: "Global" },
deleteOption: "Detach",
publicIPAllocationMethod: "Static",
},
},
],
},
],
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/toBeCreatedNetworkInterface",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"vmId": "b7a098cc-b0b8-46e8-a205-62f301a62a8f",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/toBeCreatedNetworkInterface",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"vmId": "b7a098cc-b0b8-46e8-a205-62f301a62a8f",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a VM with network interface configuration with public ip address dns settings
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"networkProfile": {
"networkApiVersion": "2020-11-01",
"networkInterfaceConfigurations": [
{
"name": "{nic-config-name}",
"properties": {
"primary": true,
"deleteOption": "Delete",
"ipConfigurations": [
{
"name": "{ip-config-name}",
"properties": {
"primary": true,
"publicIPAddressConfiguration": {
"name": "{publicIP-config-name}",
"sku": {
"name": "Basic",
"tier": "Global"
},
"properties": {
"deleteOption": "Detach",
"publicIPAllocationMethod": "Static",
"dnsSettings": {
"domainNameLabel": "aaaaa",
"domainNameLabelScope": "TenantReuse"
}
}
}
}
}
]
}
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DeleteOptions;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.DomainNameLabelScopeTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkApiVersion;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.PublicIpAddressSku;
import com.azure.resourcemanager.compute.models.PublicIpAddressSkuName;
import com.azure.resourcemanager.compute.models.PublicIpAddressSkuTier;
import com.azure.resourcemanager.compute.models.PublicIpAllocationMethod;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineNetworkInterfaceConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineNetworkInterfaceIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachinePublicIpAddressConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachinePublicIpAddressDnsSettingsConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithNetworkInterfaceConfigurationDnsSettings.json
*/
/**
* Sample code: Create a VM with network interface configuration with public ip address dns settings.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAVMWithNetworkInterfaceConfigurationWithPublicIpAddressDnsSettings(
com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkApiVersion(NetworkApiVersion.TWO_ZERO_TWO_ZERO_ONE_ONE_ZERO_ONE)
.withNetworkInterfaceConfigurations(
Arrays.asList(new VirtualMachineNetworkInterfaceConfiguration()
.withName("{nic-config-name}").withPrimary(true).withDeleteOption(DeleteOptions.DELETE)
.withIpConfigurations(Arrays.asList(new VirtualMachineNetworkInterfaceIpConfiguration()
.withName("{ip-config-name}").withPrimary(true)
.withPublicIpAddressConfiguration(new VirtualMachinePublicIpAddressConfiguration()
.withName("{publicIP-config-name}")
.withSku(new PublicIpAddressSku().withName(PublicIpAddressSkuName.BASIC)
.withTier(PublicIpAddressSkuTier.GLOBAL))
.withDeleteOption(DeleteOptions.DETACH)
.withDnsSettings(new VirtualMachinePublicIpAddressDnsSettingsConfiguration()
.withDomainNameLabel("aaaaa")
.withDomainNameLabelScope(DomainNameLabelScopeTypes.TENANT_REUSE))
.withPublicIpAllocationMethod(PublicIpAllocationMethod.STATIC))))))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_with_network_interface_configuration_dns_settings.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkApiVersion": "2020-11-01",
"networkInterfaceConfigurations": [
{
"name": "{nic-config-name}",
"properties": {
"deleteOption": "Delete",
"ipConfigurations": [
{
"name": "{ip-config-name}",
"properties": {
"primary": True,
"publicIPAddressConfiguration": {
"name": "{publicIP-config-name}",
"properties": {
"deleteOption": "Detach",
"dnsSettings": {
"domainNameLabel": "aaaaa",
"domainNameLabelScope": "TenantReuse",
},
"publicIPAllocationMethod": "Static",
},
"sku": {"name": "Basic", "tier": "Global"},
},
},
}
],
"primary": True,
},
}
],
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithNetworkInterfaceConfigurationDnsSettings.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithNetworkInterfaceConfigurationDnsSettings.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMWithNetworkInterfaceConfigurationWithPublicIPAddressDnsSettings() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("2016-Datacenter"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
Version: to.Ptr("latest"),
Offer: to.Ptr("WindowsServer"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
Name: to.Ptr("myVMosdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkAPIVersion: to.Ptr(armcompute.NetworkAPIVersionTwoThousandTwenty1101),
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineNetworkInterfaceConfiguration{
{
Name: to.Ptr("{nic-config-name}"),
Properties: &armcompute.VirtualMachineNetworkInterfaceConfigurationProperties{
Primary: to.Ptr(true),
DeleteOption: to.Ptr(armcompute.DeleteOptionsDelete),
IPConfigurations: []*armcompute.VirtualMachineNetworkInterfaceIPConfiguration{
{
Name: to.Ptr("{ip-config-name}"),
Properties: &armcompute.VirtualMachineNetworkInterfaceIPConfigurationProperties{
Primary: to.Ptr(true),
PublicIPAddressConfiguration: &armcompute.VirtualMachinePublicIPAddressConfiguration{
Name: to.Ptr("{publicIP-config-name}"),
SKU: &armcompute.PublicIPAddressSKU{
Name: to.Ptr(armcompute.PublicIPAddressSKUNameBasic),
Tier: to.Ptr(armcompute.PublicIPAddressSKUTierGlobal),
},
Properties: &armcompute.VirtualMachinePublicIPAddressConfigurationProperties{
DeleteOption: to.Ptr(armcompute.DeleteOptionsDetach),
PublicIPAllocationMethod: to.Ptr(armcompute.PublicIPAllocationMethodStatic),
DNSSettings: &armcompute.VirtualMachinePublicIPAddressDNSSettingsConfiguration{
DomainNameLabel: to.Ptr("aaaaa"),
DomainNameLabelScope: to.Ptr(armcompute.DomainNameLabelScopeTypesTenantReuse),
},
},
},
},
},
},
},
},
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/toBeCreatedNetworkInterface"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("2016-Datacenter"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("WindowsServer"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// VMID: to.Ptr("b7a098cc-b0b8-46e8-a205-62f301a62a8f"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Name: to.Ptr("myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithNetworkInterfaceConfigurationDnsSettings.json
*/
async function createAVMWithNetworkInterfaceConfigurationWithPublicIpAddressDnsSettings() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D1_v2" },
storageProfile: {
imageReference: {
sku: "2016-Datacenter",
publisher: "MicrosoftWindowsServer",
version: "latest",
offer: "WindowsServer",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Standard_LRS" },
name: "myVMosdisk",
createOption: "FromImage",
},
},
networkProfile: {
networkApiVersion: "2020-11-01",
networkInterfaceConfigurations: [
{
name: "{nic-config-name}",
primary: true,
deleteOption: "Delete",
ipConfigurations: [
{
name: "{ip-config-name}",
primary: true,
publicIPAddressConfiguration: {
name: "{publicIP-config-name}",
sku: { name: "Basic", tier: "Global" },
deleteOption: "Detach",
publicIPAllocationMethod: "Static",
dnsSettings: { domainNameLabel: "aaaaa", domainNameLabelScope: "TenantReuse" },
},
},
],
},
],
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/toBeCreatedNetworkInterface",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"vmId": "b7a098cc-b0b8-46e8-a205-62f301a62a8f",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/toBeCreatedNetworkInterface",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"vmId": "b7a098cc-b0b8-46e8-a205-62f301a62a8f",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a VM with Opportunistic Processor Mode
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D2s_v5",
"processorMode": "Opportunistic"
},
"storageProfile": {
"imageReference": {
"sku": "2019-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Premium_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.ProcessorMode;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithOpportunisticProcessorMode.json
*/
/**
* Sample code: Create a VM with Opportunistic Processor Mode.
*
* @param manager Entry point to ComputeManager.
*/
public static void
createAVMWithOpportunisticProcessorMode(com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM", new VirtualMachineInner()
.withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.fromString("Standard_D2s_v5"))
.withProcessorMode(ProcessorMode.OPPORTUNISTIC))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2019-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_with_opportunistic_processor_mode.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"processorMode": "Opportunistic", "vmSize": "Standard_D2s_v5"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2019-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Premium_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithOpportunisticProcessorMode.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithOpportunisticProcessorMode.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMWithOpportunisticProcessorMode() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypes("Standard_D2s_v5")),
ProcessorMode: to.Ptr(armcompute.ProcessorModeOpportunistic),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("2019-Datacenter"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
Version: to.Ptr("latest"),
Offer: to.Ptr("WindowsServer"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
},
Name: to.Ptr("myVMosdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("2019-Datacenter"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("WindowsServer"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
// },
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypes("Standard_D2s_v5")),
// ProcessorMode: to.Ptr(armcompute.ProcessorModeOpportunistic),
// },
// ProvisioningState: to.Ptr("Updating"),
// },
// Name: to.Ptr("myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithOpportunisticProcessorMode.json
*/
async function createAVMWithOpportunisticProcessorMode() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D2s_v5", processorMode: "Opportunistic" },
storageProfile: {
imageReference: {
sku: "2019-Datacenter",
publisher: "MicrosoftWindowsServer",
version: "latest",
offer: "WindowsServer",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Premium_LRS" },
name: "myVMosdisk",
createOption: "FromImage",
},
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2019-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"hardwareProfile": {
"vmSize": "Standard_D2s_v5",
"processorMode": "Opportunistic"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2019-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"hardwareProfile": {
"vmSize": "Standard_D2s_v5",
"processorMode": "Opportunistic"
},
"provisioningState": "Updating"
},
"name": "myVM",
"location": "westus"
}
Create a vm with password authentication.
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithPasswordAuthentication.json
*/
/**
* Sample code: Create a vm with password authentication.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAVmWithPasswordAuthentication(com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile()
.withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_with_password_authentication.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithPasswordAuthentication.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithPasswordAuthentication.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMWithPasswordAuthentication() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("2016-Datacenter"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
Version: to.Ptr("latest"),
Offer: to.Ptr("WindowsServer"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
Name: to.Ptr("myVMosdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("2016-Datacenter"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("WindowsServer"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// VMID: to.Ptr("b248db33-62ba-4d2d-b791-811e075ee0f5"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Name: to.Ptr("myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithPasswordAuthentication.json
*/
async function createAVmWithPasswordAuthentication() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D1_v2" },
storageProfile: {
imageReference: {
sku: "2016-Datacenter",
publisher: "MicrosoftWindowsServer",
version: "latest",
offer: "WindowsServer",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Standard_LRS" },
name: "myVMosdisk",
createOption: "FromImage",
},
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"vmId": "b248db33-62ba-4d2d-b791-811e075ee0f5",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"vmId": "b248db33-62ba-4d2d-b791-811e075ee0f5",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a vm with premium storage.
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Premium_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithPremiumStorage.json
*/
/**
* Sample code: Create a vm with premium storage.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAVmWithPremiumStorage(com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile()
.withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_with_premium_storage.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Premium_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithPremiumStorage.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithPremiumStorage.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMWithPremiumStorage() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("2016-Datacenter"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
Version: to.Ptr("latest"),
Offer: to.Ptr("WindowsServer"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
},
Name: to.Ptr("myVMosdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("2016-Datacenter"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("WindowsServer"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
// },
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// VMID: to.Ptr("a149cd25-409f-41af-8088-275f5486bc93"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Name: to.Ptr("myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithPremiumStorage.json
*/
async function createAVmWithPremiumStorage() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D1_v2" },
storageProfile: {
imageReference: {
sku: "2016-Datacenter",
publisher: "MicrosoftWindowsServer",
version: "latest",
offer: "WindowsServer",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Premium_LRS" },
name: "myVMosdisk",
createOption: "FromImage",
},
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a VM with ProxyAgent Settings of enabled and mode.
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"securityProfile": {
"proxyAgentSettings": {
"enabled": true,
"wireServer": {
"mode": "Audit"
},
"imds": {
"mode": "Audit"
}
}
},
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "2019-Datacenter",
"version": "latest"
},
"osDisk": {
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "StandardSSD_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.HostEndpointSettings;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.Modes;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.ProxyAgentSettings;
import com.azure.resourcemanager.compute.models.SecurityProfile;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithProxyAgentSettings.json
*/
/**
* Sample code: Create a VM with ProxyAgent Settings of enabled and mode.
*
* @param manager Entry point to ComputeManager.
*/
public static void
createAVMWithProxyAgentSettingsOfEnabledAndMode(com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2019-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS))))
.withOsProfile(new OSProfile()
.withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile().withProxyAgentSettings(new ProxyAgentSettings()
.withEnabled(true).withWireServer(new HostEndpointSettings().withMode(Modes.AUDIT))
.withImds(new HostEndpointSettings().withMode(Modes.AUDIT)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_with_proxy_agent_settings.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D2s_v3"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"securityProfile": {
"proxyAgentSettings": {"enabled": True, "imds": {"mode": "Audit"}, "wireServer": {"mode": "Audit"}}
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2019-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadOnly",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "StandardSSD_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithProxyAgentSettings.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithProxyAgentSettings.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMWithProxyAgentSettingsOfEnabledAndMode() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2SV3),
},
SecurityProfile: &armcompute.SecurityProfile{
ProxyAgentSettings: &armcompute.ProxyAgentSettings{
Enabled: to.Ptr(true),
WireServer: &armcompute.HostEndpointSettings{
Mode: to.Ptr(armcompute.ModesAudit),
},
Imds: &armcompute.HostEndpointSettings{
Mode: to.Ptr(armcompute.ModesAudit),
},
},
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
Publisher: to.Ptr("MicrosoftWindowsServer"),
Offer: to.Ptr("WindowsServer"),
SKU: to.Ptr("2019-Datacenter"),
Version: to.Ptr("latest"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadOnly),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardSSDLRS),
},
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
Name: to.Ptr("myVMosdisk"),
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// Offer: to.Ptr("WindowsServer"),
// SKU: to.Ptr("2019-Datacenter"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadOnly),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardSSDLRS),
// },
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// SecurityProfile: &armcompute.SecurityProfile{
// ProxyAgentSettings: &armcompute.ProxyAgentSettings{
// Enabled: to.Ptr(true),
// WireServer: &armcompute.HostEndpointSettings{
// Mode: to.Ptr(armcompute.ModesAudit),
// },
// Imds: &armcompute.HostEndpointSettings{
// Mode: to.Ptr(armcompute.ModesAudit),
// },
// },
// },
// VMID: to.Ptr("5c0d55a7-c407-4ed6-bf7d-ddb810267c85"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2SV3),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithProxyAgentSettings.json
*/
async function createAVMWithProxyAgentSettingsOfEnabledAndMode() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D2s_v3" },
securityProfile: {
proxyAgentSettings: { enabled: true, wireServer: { mode: "Audit" }, imds: { mode: "Audit" } },
},
storageProfile: {
imageReference: {
publisher: "MicrosoftWindowsServer",
offer: "WindowsServer",
sku: "2019-Datacenter",
version: "latest",
},
osDisk: {
caching: "ReadOnly",
managedDisk: { storageAccountType: "StandardSSD_LRS" },
createOption: "FromImage",
name: "myVMosdisk",
},
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "2019-Datacenter",
"version": "latest"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "StandardSSD_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"securityProfile": {
"proxyAgentSettings": {
"enabled": true,
"wireServer": {
"mode": "Audit"
},
"imds": {
"mode": "Audit"
}
}
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "2019-Datacenter",
"version": "latest"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "StandardSSD_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"securityProfile": {
"proxyAgentSettings": {
"enabled": true,
"wireServer": {
"mode": "Audit"
},
"imds": {
"mode": "Audit"
}
}
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
Create a vm with Scheduled Events Profile
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"scheduledEventsPolicy": {
"scheduledEventsAdditionalPublishingTargets": {
"eventGridAndResourceGraph": {
"enable": true,
"scheduledEventsApiVersion": "2020-07-01"
}
},
"userInitiatedRedeploy": {
"automaticallyApprove": true
},
"userInitiatedReboot": {
"automaticallyApprove": true
},
"allInstancesDown": {
"automaticallyApprove": true
}
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://{existing-storage-account-name}.blob.core.windows.net",
"enabled": true
}
},
"scheduledEventsProfile": {
"terminateNotificationProfile": {
"notBeforeTimeout": "PT10M",
"enable": true
},
"osImageNotificationProfile": {
"notBeforeTimeout": "PT15M",
"enable": true
}
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.AllInstancesDown;
import com.azure.resourcemanager.compute.models.BootDiagnostics;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiagnosticsProfile;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.EventGridAndResourceGraph;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSImageNotificationProfile;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.ScheduledEventsAdditionalPublishingTargets;
import com.azure.resourcemanager.compute.models.ScheduledEventsPolicy;
import com.azure.resourcemanager.compute.models.ScheduledEventsProfile;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.TerminateNotificationProfile;
import com.azure.resourcemanager.compute.models.UserInitiatedReboot;
import com.azure.resourcemanager.compute.models.UserInitiatedRedeploy;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithScheduledEventsProfile.json
*/
/**
* Sample code: Create a vm with Scheduled Events Profile.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAVmWithScheduledEventsProfile(com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM", new VirtualMachineInner()
.withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withScheduledEventsPolicy(new ScheduledEventsPolicy()
.withUserInitiatedRedeploy(new UserInitiatedRedeploy().withAutomaticallyApprove(true))
.withUserInitiatedReboot(new UserInitiatedReboot().withAutomaticallyApprove(true))
.withScheduledEventsAdditionalPublishingTargets(
new ScheduledEventsAdditionalPublishingTargets().withEventGridAndResourceGraph(
new EventGridAndResourceGraph().withEnable(true).withScheduledEventsApiVersion("2020-07-01")))
.withAllInstancesDown(new AllInstancesDown().withAutomaticallyApprove(true)))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics().withEnabled(true)
.withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withScheduledEventsProfile(new ScheduledEventsProfile()
.withTerminateNotificationProfile(
new TerminateNotificationProfile().withNotBeforeTimeout("PT10M").withEnable(true))
.withOsImageNotificationProfile(
new OSImageNotificationProfile().withNotBeforeTimeout("PT15M").withEnable(true))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_with_scheduled_events_profile.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": True,
"storageUri": "http://{existing-storage-account-name}.blob.core.windows.net",
}
},
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"scheduledEventsPolicy": {
"allInstancesDown": {"automaticallyApprove": True},
"scheduledEventsAdditionalPublishingTargets": {
"eventGridAndResourceGraph": {"enable": True, "scheduledEventsApiVersion": "2020-07-01"}
},
"userInitiatedReboot": {"automaticallyApprove": True},
"userInitiatedRedeploy": {"automaticallyApprove": True},
},
"scheduledEventsProfile": {
"osImageNotificationProfile": {"enable": True, "notBeforeTimeout": "PT15M"},
"terminateNotificationProfile": {"enable": True, "notBeforeTimeout": "PT10M"},
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithScheduledEventsProfile.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithScheduledEventsProfile.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMWithScheduledEventsProfile() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
ScheduledEventsPolicy: &armcompute.ScheduledEventsPolicy{
ScheduledEventsAdditionalPublishingTargets: &armcompute.ScheduledEventsAdditionalPublishingTargets{
EventGridAndResourceGraph: &armcompute.EventGridAndResourceGraph{
Enable: to.Ptr(true),
ScheduledEventsAPIVersion: to.Ptr("2020-07-01"),
},
},
UserInitiatedRedeploy: &armcompute.UserInitiatedRedeploy{
AutomaticallyApprove: to.Ptr(true),
},
UserInitiatedReboot: &armcompute.UserInitiatedReboot{
AutomaticallyApprove: to.Ptr(true),
},
AllInstancesDown: &armcompute.AllInstancesDown{
AutomaticallyApprove: to.Ptr(true),
},
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("2016-Datacenter"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
Version: to.Ptr("latest"),
Offer: to.Ptr("WindowsServer"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
Name: to.Ptr("myVMosdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
DiagnosticsProfile: &armcompute.DiagnosticsProfile{
BootDiagnostics: &armcompute.BootDiagnostics{
StorageURI: to.Ptr("http://{existing-storage-account-name}.blob.core.windows.net"),
Enabled: to.Ptr(true),
},
},
ScheduledEventsProfile: &armcompute.ScheduledEventsProfile{
TerminateNotificationProfile: &armcompute.TerminateNotificationProfile{
NotBeforeTimeout: to.Ptr("PT10M"),
Enable: to.Ptr(true),
},
OSImageNotificationProfile: &armcompute.OSImageNotificationProfile{
NotBeforeTimeout: to.Ptr("PT15M"),
Enable: to.Ptr(true),
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("2016-Datacenter"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("WindowsServer"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// DiagnosticsProfile: &armcompute.DiagnosticsProfile{
// BootDiagnostics: &armcompute.BootDiagnostics{
// StorageURI: to.Ptr("http://nsgdiagnostic.blob.core.windows.net"),
// Enabled: to.Ptr(true),
// },
// },
// VMID: to.Ptr("676420ba-7a24-4bfe-80bd-9c841ee184fa"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// ScheduledEventsPolicy: &armcompute.ScheduledEventsPolicy{
// ScheduledEventsAdditionalPublishingTargets: &armcompute.ScheduledEventsAdditionalPublishingTargets{
// EventGridAndResourceGraph: &armcompute.EventGridAndResourceGraph{
// Enable: to.Ptr(true),
// ScheduledEventsAPIVersion: to.Ptr("2020-07-01"),
// },
// },
// UserInitiatedRedeploy: &armcompute.UserInitiatedRedeploy{
// AutomaticallyApprove: to.Ptr(true),
// },
// UserInitiatedReboot: &armcompute.UserInitiatedReboot{
// AutomaticallyApprove: to.Ptr(true),
// },
// AllInstancesDown: &armcompute.AllInstancesDown{
// AutomaticallyApprove: to.Ptr(true),
// },
// },
// ScheduledEventsProfile: &armcompute.ScheduledEventsProfile{
// TerminateNotificationProfile: &armcompute.TerminateNotificationProfile{
// NotBeforeTimeout: to.Ptr("PT10M"),
// Enable: to.Ptr(true),
// },
// OSImageNotificationProfile: &armcompute.OSImageNotificationProfile{
// NotBeforeTimeout: to.Ptr("PT15M"),
// Enable: to.Ptr(true),
// },
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Name: to.Ptr("myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithScheduledEventsProfile.json
*/
async function createAVmWithScheduledEventsProfile() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D1_v2" },
scheduledEventsPolicy: {
scheduledEventsAdditionalPublishingTargets: {
eventGridAndResourceGraph: { enable: true, scheduledEventsApiVersion: "2020-07-01" },
},
userInitiatedRedeploy: { automaticallyApprove: true },
userInitiatedReboot: { automaticallyApprove: true },
allInstancesDown: { automaticallyApprove: true },
},
storageProfile: {
imageReference: {
sku: "2016-Datacenter",
publisher: "MicrosoftWindowsServer",
version: "latest",
offer: "WindowsServer",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Standard_LRS" },
name: "myVMosdisk",
createOption: "FromImage",
},
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
diagnosticsProfile: {
bootDiagnostics: {
storageUri: "http://{existing-storage-account-name}.blob.core.windows.net",
enabled: true,
},
},
scheduledEventsProfile: {
terminateNotificationProfile: { notBeforeTimeout: "PT10M", enable: true },
osImageNotificationProfile: { notBeforeTimeout: "PT15M", enable: true },
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://nsgdiagnostic.blob.core.windows.net",
"enabled": true
}
},
"vmId": "676420ba-7a24-4bfe-80bd-9c841ee184fa",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"scheduledEventsPolicy": {
"scheduledEventsAdditionalPublishingTargets": {
"eventGridAndResourceGraph": {
"enable": true,
"scheduledEventsApiVersion": "2020-07-01"
}
},
"userInitiatedRedeploy": {
"automaticallyApprove": true
},
"userInitiatedReboot": {
"automaticallyApprove": true
},
"allInstancesDown": {
"automaticallyApprove": true
}
},
"scheduledEventsProfile": {
"terminateNotificationProfile": {
"notBeforeTimeout": "PT10M",
"enable": true
},
"osImageNotificationProfile": {
"notBeforeTimeout": "PT15M",
"enable": true
}
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://nsgdiagnostic.blob.core.windows.net",
"enabled": true
}
},
"vmId": "676420ba-7a24-4bfe-80bd-9c841ee184fa",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"scheduledEventsPolicy": {
"scheduledEventsAdditionalPublishingTargets": {
"eventGridAndResourceGraph": {
"enable": true,
"scheduledEventsApiVersion": "2020-07-01"
}
},
"userInitiatedRedeploy": {
"automaticallyApprove": true
},
"userInitiatedReboot": {
"automaticallyApprove": true
},
"allInstancesDown": {
"automaticallyApprove": true
}
},
"scheduledEventsProfile": {
"terminateNotificationProfile": {
"notBeforeTimeout": "PT10M",
"enable": true
},
"osImageNotificationProfile": {
"notBeforeTimeout": "PT15M",
"enable": true
}
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a VM with securityType ConfidentialVM with Customer Managed Keys
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_DC2as_v5"
},
"securityProfile": {
"uefiSettings": {
"secureBootEnabled": true,
"vTpmEnabled": true
},
"securityType": "ConfidentialVM"
},
"storageProfile": {
"imageReference": {
"sku": "windows-cvm",
"publisher": "MicrosoftWindowsServer",
"version": "17763.2183.2109130127",
"offer": "2019-datacenter-cvm"
},
"osDisk": {
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "StandardSSD_LRS",
"securityProfile": {
"securityEncryptionType": "DiskWithVMGuestState",
"diskEncryptionSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
}
}
},
"createOption": "FromImage",
"name": "myVMosdisk"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.DiskEncryptionSetParameters;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.SecurityEncryptionTypes;
import com.azure.resourcemanager.compute.models.SecurityProfile;
import com.azure.resourcemanager.compute.models.SecurityTypes;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.UefiSettings;
import com.azure.resourcemanager.compute.models.VMDiskSecurityProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVMWithCustomerManagedKeys.
* json
*/
/**
* Sample code: Create a VM with securityType ConfidentialVM with Customer Managed Keys.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAVMWithSecurityTypeConfidentialVMWithCustomerManagedKeys(
com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM", new VirtualMachineInner()
.withLocation("westus")
.withHardwareProfile(
new HardwareProfile().withVmSize(VirtualMachineSizeTypes.fromString("Standard_DC2as_v5")))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("2019-datacenter-cvm").withSku("windows-cvm").withVersion("17763.2183.2109130127"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(new ManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS)
.withSecurityProfile(new VMDiskSecurityProfile()
.withSecurityEncryptionType(SecurityEncryptionTypes.DISK_WITH_VMGUEST_STATE)
.withDiskEncryptionSet(new DiskEncryptionSetParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"))))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withUefiSettings(new UefiSettings().withSecureBootEnabled(true).withVTpmEnabled(true))
.withSecurityType(SecurityTypes.CONFIDENTIAL_VM)),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_with_security_type_confidential_vm_with_customer_managed_keys.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_DC2as_v5"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"securityProfile": {
"securityType": "ConfidentialVM",
"uefiSettings": {"secureBootEnabled": True, "vTpmEnabled": True},
},
"storageProfile": {
"imageReference": {
"offer": "2019-datacenter-cvm",
"publisher": "MicrosoftWindowsServer",
"sku": "windows-cvm",
"version": "17763.2183.2109130127",
},
"osDisk": {
"caching": "ReadOnly",
"createOption": "FromImage",
"managedDisk": {
"securityProfile": {
"diskEncryptionSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
},
"securityEncryptionType": "DiskWithVMGuestState",
},
"storageAccountType": "StandardSSD_LRS",
},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVMWithCustomerManagedKeys.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVMWithCustomerManagedKeys.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMWithSecurityTypeConfidentialVMWithCustomerManagedKeys() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypes("Standard_DC2as_v5")),
},
SecurityProfile: &armcompute.SecurityProfile{
UefiSettings: &armcompute.UefiSettings{
SecureBootEnabled: to.Ptr(true),
VTpmEnabled: to.Ptr(true),
},
SecurityType: to.Ptr(armcompute.SecurityTypesConfidentialVM),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("windows-cvm"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
Version: to.Ptr("17763.2183.2109130127"),
Offer: to.Ptr("2019-datacenter-cvm"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadOnly),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardSSDLRS),
SecurityProfile: &armcompute.VMDiskSecurityProfile{
SecurityEncryptionType: to.Ptr(armcompute.SecurityEncryptionTypesDiskWithVMGuestState),
DiskEncryptionSet: &armcompute.DiskEncryptionSetParameters{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"),
},
},
},
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
Name: to.Ptr("myVMosdisk"),
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("windows-cvm"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// Version: to.Ptr("17763.2183.2109130127"),
// Offer: to.Ptr("2019-datacenter-cvm"),
// },
// OSDisk: &armcompute.OSDisk{
// Caching: to.Ptr(armcompute.CachingTypesReadOnly),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardSSDLRS),
// SecurityProfile: &armcompute.VMDiskSecurityProfile{
// SecurityEncryptionType: to.Ptr(armcompute.SecurityEncryptionTypesDiskWithVMGuestState),
// DiskEncryptionSet: &armcompute.DiskEncryptionSetParameters{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"),
// },
// },
// },
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// SecurityProfile: &armcompute.SecurityProfile{
// UefiSettings: &armcompute.UefiSettings{
// SecureBootEnabled: to.Ptr(true),
// VTpmEnabled: to.Ptr(true),
// },
// SecurityType: to.Ptr(armcompute.SecurityTypesConfidentialVM),
// },
// VMID: to.Ptr("5c0d55a7-c407-4ed6-bf7d-ddb810267c85"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypes("Standard_DC2as_v5")),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVMWithCustomerManagedKeys.json
*/
async function createAVMWithSecurityTypeConfidentialVMWithCustomerManagedKeys() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_DC2as_v5" },
securityProfile: {
uefiSettings: { secureBootEnabled: true, vTpmEnabled: true },
securityType: "ConfidentialVM",
},
storageProfile: {
imageReference: {
sku: "windows-cvm",
publisher: "MicrosoftWindowsServer",
version: "17763.2183.2109130127",
offer: "2019-datacenter-cvm",
},
osDisk: {
caching: "ReadOnly",
managedDisk: {
storageAccountType: "StandardSSD_LRS",
securityProfile: {
securityEncryptionType: "DiskWithVMGuestState",
diskEncryptionSet: {
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}",
},
},
},
createOption: "FromImage",
name: "myVMosdisk",
},
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "windows-cvm",
"publisher": "MicrosoftWindowsServer",
"version": "17763.2183.2109130127",
"offer": "2019-datacenter-cvm"
},
"osDisk": {
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "StandardSSD_LRS",
"securityProfile": {
"securityEncryptionType": "DiskWithVMGuestState",
"diskEncryptionSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
}
}
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"securityProfile": {
"uefiSettings": {
"secureBootEnabled": true,
"vTpmEnabled": true
},
"securityType": "ConfidentialVM"
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DC2as_v5"
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "windows-cvm",
"publisher": "MicrosoftWindowsServer",
"version": "17763.2183.2109130127",
"offer": "2019-datacenter-cvm"
},
"osDisk": {
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "StandardSSD_LRS",
"securityProfile": {
"securityEncryptionType": "DiskWithVMGuestState",
"diskEncryptionSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
}
}
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"securityProfile": {
"uefiSettings": {
"secureBootEnabled": true,
"vTpmEnabled": true
},
"securityType": "ConfidentialVM"
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DC2as_v5"
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
Create a VM with securityType ConfidentialVM with NonPersistedTPM securityEncryptionType
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_DC2es_v5"
},
"securityProfile": {
"uefiSettings": {
"secureBootEnabled": false,
"vTpmEnabled": true
},
"securityType": "ConfidentialVM"
},
"storageProfile": {
"imageReference": {
"sku": "linux-cvm",
"publisher": "UbuntuServer",
"version": "17763.2183.2109130127",
"offer": "2022-datacenter-cvm"
},
"osDisk": {
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "StandardSSD_LRS",
"securityProfile": {
"securityEncryptionType": "NonPersistedTPM"
}
},
"createOption": "FromImage",
"name": "myVMosdisk"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.SecurityEncryptionTypes;
import com.azure.resourcemanager.compute.models.SecurityProfile;
import com.azure.resourcemanager.compute.models.SecurityTypes;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.UefiSettings;
import com.azure.resourcemanager.compute.models.VMDiskSecurityProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVMWithNonPersistedTPM.json
*/
/**
* Sample code: Create a VM with securityType ConfidentialVM with NonPersistedTPM securityEncryptionType.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAVMWithSecurityTypeConfidentialVMWithNonPersistedTPMSecurityEncryptionType(
com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(
new HardwareProfile().withVmSize(VirtualMachineSizeTypes.fromString("Standard_DC2es_v5")))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("UbuntuServer")
.withOffer("2022-datacenter-cvm").withSku("linux-cvm").withVersion("17763.2183.2109130127"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS)
.withSecurityProfile(new VMDiskSecurityProfile()
.withSecurityEncryptionType(SecurityEncryptionTypes.NON_PERSISTED_TPM)))))
.withOsProfile(new OSProfile()
.withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withUefiSettings(new UefiSettings().withSecureBootEnabled(false).withVTpmEnabled(true))
.withSecurityType(SecurityTypes.CONFIDENTIAL_VM)),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_with_security_type_confidential_vm_with_non_persisted_tpm.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_DC2es_v5"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"securityProfile": {
"securityType": "ConfidentialVM",
"uefiSettings": {"secureBootEnabled": False, "vTpmEnabled": True},
},
"storageProfile": {
"imageReference": {
"offer": "2022-datacenter-cvm",
"publisher": "UbuntuServer",
"sku": "linux-cvm",
"version": "17763.2183.2109130127",
},
"osDisk": {
"caching": "ReadOnly",
"createOption": "FromImage",
"managedDisk": {
"securityProfile": {"securityEncryptionType": "NonPersistedTPM"},
"storageAccountType": "StandardSSD_LRS",
},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVMWithNonPersistedTPM.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVMWithNonPersistedTPM.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMWithSecurityTypeConfidentialVMWithNonPersistedTpmSecurityEncryptionType() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypes("Standard_DC2es_v5")),
},
SecurityProfile: &armcompute.SecurityProfile{
UefiSettings: &armcompute.UefiSettings{
SecureBootEnabled: to.Ptr(false),
VTpmEnabled: to.Ptr(true),
},
SecurityType: to.Ptr(armcompute.SecurityTypesConfidentialVM),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("linux-cvm"),
Publisher: to.Ptr("UbuntuServer"),
Version: to.Ptr("17763.2183.2109130127"),
Offer: to.Ptr("2022-datacenter-cvm"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadOnly),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardSSDLRS),
SecurityProfile: &armcompute.VMDiskSecurityProfile{
SecurityEncryptionType: to.Ptr(armcompute.SecurityEncryptionTypesNonPersistedTPM),
},
},
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
Name: to.Ptr("myVMosdisk"),
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("linux-cvm"),
// Publisher: to.Ptr("UbuntuServer"),
// Version: to.Ptr("17763.2183.2109130127"),
// Offer: to.Ptr("2022-datacenter-cvm"),
// },
// OSDisk: &armcompute.OSDisk{
// Caching: to.Ptr(armcompute.CachingTypesReadOnly),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardSSDLRS),
// SecurityProfile: &armcompute.VMDiskSecurityProfile{
// SecurityEncryptionType: to.Ptr(armcompute.SecurityEncryptionTypesNonPersistedTPM),
// },
// },
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// SecurityProfile: &armcompute.SecurityProfile{
// UefiSettings: &armcompute.UefiSettings{
// SecureBootEnabled: to.Ptr(false),
// VTpmEnabled: to.Ptr(true),
// },
// SecurityType: to.Ptr(armcompute.SecurityTypesConfidentialVM),
// },
// VMID: to.Ptr("5c0d55a7-c407-4ed6-bf7d-ddb810267c85"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypes("Standard_DC2es_v5")),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVMWithNonPersistedTPM.json
*/
async function createAVMWithSecurityTypeConfidentialVMWithNonPersistedTPMSecurityEncryptionType() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_DC2es_v5" },
securityProfile: {
uefiSettings: { secureBootEnabled: false, vTpmEnabled: true },
securityType: "ConfidentialVM",
},
storageProfile: {
imageReference: {
sku: "linux-cvm",
publisher: "UbuntuServer",
version: "17763.2183.2109130127",
offer: "2022-datacenter-cvm",
},
osDisk: {
caching: "ReadOnly",
managedDisk: {
storageAccountType: "StandardSSD_LRS",
securityProfile: { securityEncryptionType: "NonPersistedTPM" },
},
createOption: "FromImage",
name: "myVMosdisk",
},
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "linux-cvm",
"publisher": "UbuntuServer",
"version": "17763.2183.2109130127",
"offer": "2022-datacenter-cvm"
},
"osDisk": {
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "StandardSSD_LRS",
"securityProfile": {
"securityEncryptionType": "NonPersistedTPM"
}
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"securityProfile": {
"uefiSettings": {
"secureBootEnabled": false,
"vTpmEnabled": true
},
"securityType": "ConfidentialVM"
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DC2es_v5"
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "linux-cvm",
"publisher": "UbuntuServer",
"version": "17763.2183.2109130127",
"offer": "2022-datacenter-cvm"
},
"osDisk": {
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "StandardSSD_LRS",
"securityProfile": {
"securityEncryptionType": "NonPersistedTPM"
}
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"securityProfile": {
"uefiSettings": {
"secureBootEnabled": false,
"vTpmEnabled": true
},
"securityType": "ConfidentialVM"
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DC2es_v5"
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_DC2as_v5"
},
"securityProfile": {
"uefiSettings": {
"secureBootEnabled": true,
"vTpmEnabled": true
},
"securityType": "ConfidentialVM"
},
"storageProfile": {
"imageReference": {
"sku": "windows-cvm",
"publisher": "MicrosoftWindowsServer",
"version": "17763.2183.2109130127",
"offer": "2019-datacenter-cvm"
},
"osDisk": {
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "StandardSSD_LRS",
"securityProfile": {
"securityEncryptionType": "DiskWithVMGuestState"
}
},
"createOption": "FromImage",
"name": "myVMosdisk"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.SecurityEncryptionTypes;
import com.azure.resourcemanager.compute.models.SecurityProfile;
import com.azure.resourcemanager.compute.models.SecurityTypes;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.UefiSettings;
import com.azure.resourcemanager.compute.models.VMDiskSecurityProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVM.json
*/
/**
* Sample code: Create a VM with securityType ConfidentialVM with Platform Managed Keys.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAVMWithSecurityTypeConfidentialVMWithPlatformManagedKeys(
com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(
new HardwareProfile().withVmSize(VirtualMachineSizeTypes.fromString("Standard_DC2as_v5")))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("2019-datacenter-cvm").withSku("windows-cvm").withVersion("17763.2183.2109130127"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS)
.withSecurityProfile(new VMDiskSecurityProfile()
.withSecurityEncryptionType(SecurityEncryptionTypes.DISK_WITH_VMGUEST_STATE)))))
.withOsProfile(new OSProfile()
.withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withUefiSettings(new UefiSettings().withSecureBootEnabled(true).withVTpmEnabled(true))
.withSecurityType(SecurityTypes.CONFIDENTIAL_VM)),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_with_security_type_confidential_vm.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_DC2as_v5"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"securityProfile": {
"securityType": "ConfidentialVM",
"uefiSettings": {"secureBootEnabled": True, "vTpmEnabled": True},
},
"storageProfile": {
"imageReference": {
"offer": "2019-datacenter-cvm",
"publisher": "MicrosoftWindowsServer",
"sku": "windows-cvm",
"version": "17763.2183.2109130127",
},
"osDisk": {
"caching": "ReadOnly",
"createOption": "FromImage",
"managedDisk": {
"securityProfile": {"securityEncryptionType": "DiskWithVMGuestState"},
"storageAccountType": "StandardSSD_LRS",
},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVM.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVM.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMWithSecurityTypeConfidentialVMWithPlatformManagedKeys() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypes("Standard_DC2as_v5")),
},
SecurityProfile: &armcompute.SecurityProfile{
UefiSettings: &armcompute.UefiSettings{
SecureBootEnabled: to.Ptr(true),
VTpmEnabled: to.Ptr(true),
},
SecurityType: to.Ptr(armcompute.SecurityTypesConfidentialVM),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("windows-cvm"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
Version: to.Ptr("17763.2183.2109130127"),
Offer: to.Ptr("2019-datacenter-cvm"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadOnly),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardSSDLRS),
SecurityProfile: &armcompute.VMDiskSecurityProfile{
SecurityEncryptionType: to.Ptr(armcompute.SecurityEncryptionTypesDiskWithVMGuestState),
},
},
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
Name: to.Ptr("myVMosdisk"),
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("windows-cvm"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// Version: to.Ptr("17763.2183.2109130127"),
// Offer: to.Ptr("2019-datacenter-cvm"),
// },
// OSDisk: &armcompute.OSDisk{
// Caching: to.Ptr(armcompute.CachingTypesReadOnly),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardSSDLRS),
// SecurityProfile: &armcompute.VMDiskSecurityProfile{
// SecurityEncryptionType: to.Ptr(armcompute.SecurityEncryptionTypesDiskWithVMGuestState),
// },
// },
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// SecurityProfile: &armcompute.SecurityProfile{
// UefiSettings: &armcompute.UefiSettings{
// SecureBootEnabled: to.Ptr(true),
// VTpmEnabled: to.Ptr(true),
// },
// SecurityType: to.Ptr(armcompute.SecurityTypesConfidentialVM),
// },
// VMID: to.Ptr("5c0d55a7-c407-4ed6-bf7d-ddb810267c85"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypes("Standard_DC2as_v5")),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVM.json
*/
async function createAVMWithSecurityTypeConfidentialVMWithPlatformManagedKeys() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_DC2as_v5" },
securityProfile: {
uefiSettings: { secureBootEnabled: true, vTpmEnabled: true },
securityType: "ConfidentialVM",
},
storageProfile: {
imageReference: {
sku: "windows-cvm",
publisher: "MicrosoftWindowsServer",
version: "17763.2183.2109130127",
offer: "2019-datacenter-cvm",
},
osDisk: {
caching: "ReadOnly",
managedDisk: {
storageAccountType: "StandardSSD_LRS",
securityProfile: { securityEncryptionType: "DiskWithVMGuestState" },
},
createOption: "FromImage",
name: "myVMosdisk",
},
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "windows-cvm",
"publisher": "MicrosoftWindowsServer",
"version": "17763.2183.2109130127",
"offer": "2019-datacenter-cvm"
},
"osDisk": {
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "StandardSSD_LRS",
"securityProfile": {
"securityEncryptionType": "DiskWithVMGuestState"
}
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"securityProfile": {
"uefiSettings": {
"secureBootEnabled": true,
"vTpmEnabled": true
},
"securityType": "ConfidentialVM"
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DC2as_v5"
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "windows-cvm",
"publisher": "MicrosoftWindowsServer",
"version": "17763.2183.2109130127",
"offer": "2019-datacenter-cvm"
},
"osDisk": {
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "StandardSSD_LRS",
"securityProfile": {
"securityEncryptionType": "DiskWithVMGuestState"
}
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"securityProfile": {
"uefiSettings": {
"secureBootEnabled": true,
"vTpmEnabled": true
},
"securityType": "ConfidentialVM"
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DC2as_v5"
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
Create a vm with SpotPlus priority
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D2s_v5"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
},
"priority": "SpotPlus",
"evictionPolicy": "Deallocate",
"billingProfile": {
"maxPrice": -1
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.BillingProfile;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineEvictionPolicyTypes;
import com.azure.resourcemanager.compute.models.VirtualMachinePriorityTypes;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithSpotPlusPriority.json
*/
/**
* Sample code: Create a vm with SpotPlus priority.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAVmWithSpotPlusPriority(com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(
new HardwareProfile().withVmSize(VirtualMachineSizeTypes.fromString("Standard_D2s_v5")))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile()
.withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withPriority(VirtualMachinePriorityTypes.SPOT_PLUS)
.withEvictionPolicy(VirtualMachineEvictionPolicyTypes.DEALLOCATE).withBillingProfile(
new BillingProfile().withMaxPrice(-1.0D)),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_with_spot_plus_priority.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"billingProfile": {"maxPrice": -1},
"evictionPolicy": "Deallocate",
"hardwareProfile": {"vmSize": "Standard_D2s_v5"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"priority": "SpotPlus",
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithSpotPlusPriority.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithSpotPlusPriority.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMWithSpotPlusPriority() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypes("Standard_D2s_v5")),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("2016-Datacenter"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
Version: to.Ptr("latest"),
Offer: to.Ptr("WindowsServer"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
Name: to.Ptr("myVMosdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
Priority: to.Ptr(armcompute.VirtualMachinePriorityTypesSpotPlus),
EvictionPolicy: to.Ptr(armcompute.VirtualMachineEvictionPolicyTypesDeallocate),
BillingProfile: &armcompute.BillingProfile{
MaxPrice: to.Ptr[float64](-1),
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("2016-Datacenter"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("WindowsServer"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// VMID: to.Ptr("a9b2c3d4-e5f6-7890-abcd-ef1234567890"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypes("Standard_D2s_v5")),
// },
// Priority: to.Ptr(armcompute.VirtualMachinePriorityTypesSpotPlus),
// EvictionPolicy: to.Ptr(armcompute.VirtualMachineEvictionPolicyTypesDeallocate),
// BillingProfile: &armcompute.BillingProfile{
// MaxPrice: to.Ptr[float64](-1),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Name: to.Ptr("myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithSpotPlusPriority.json
*/
async function createAVmWithSpotPlusPriority() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D2s_v5" },
storageProfile: {
imageReference: {
sku: "2016-Datacenter",
publisher: "MicrosoftWindowsServer",
version: "latest",
offer: "WindowsServer",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Standard_LRS" },
name: "myVMosdisk",
createOption: "FromImage",
},
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
priority: "SpotPlus",
evictionPolicy: "Deallocate",
billingProfile: { maxPrice: -1 },
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"vmId": "a9b2c3d4-e5f6-7890-abcd-ef1234567890",
"hardwareProfile": {
"vmSize": "Standard_D2s_v5"
},
"priority": "SpotPlus",
"evictionPolicy": "Deallocate",
"billingProfile": {
"maxPrice": -1
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"vmId": "a9b2c3d4-e5f6-7890-abcd-ef1234567890",
"hardwareProfile": {
"vmSize": "Standard_D2s_v5"
},
"priority": "SpotPlus",
"evictionPolicy": "Deallocate",
"billingProfile": {
"maxPrice": -1
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a vm with ssh authentication.
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "{image_sku}",
"publisher": "{image_publisher}",
"version": "latest",
"offer": "{image_offer}"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"linuxConfiguration": {
"ssh": {
"publicKeys": [
{
"path": "/home/{your-username}/.ssh/authorized_keys",
"keyData": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCeClRAk2ipUs/l5voIsDC5q9RI+YSRd1Bvd/O+axgY4WiBzG+4FwJWZm/mLLe5DoOdHQwmU2FrKXZSW4w2sYE70KeWnrFViCOX5MTVvJgPE8ClugNl8RWth/tU849DvM9sT7vFgfVSHcAS2yDRyDlueii+8nF2ym8XWAPltFVCyLHRsyBp5YPqK8JFYIa1eybKsY3hEAxRCA+/7bq8et+Gj3coOsuRmrehav7rE6N12Pb80I6ofa6SM5XNYq4Xk0iYNx7R3kdz0Jj9XgZYWjAHjJmT0gTRoOnt6upOuxK7xI/ykWrllgpXrCPu3Ymz+c+ujaqcxDopnAl2lmf69/J1"
}
]
},
"disablePasswordAuthentication": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.LinuxConfiguration;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.SshConfiguration;
import com.azure.resourcemanager.compute.models.SshPublicKey;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithSshAuthentication.json
*/
/**
* Sample code: Create a vm with ssh authentication.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAVmWithSshAuthentication(com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("{image_publisher}")
.withOffer("{image_offer}").withSku("{image_sku}").withVersion("latest"))
.withOsDisk(
new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withLinuxConfiguration(new LinuxConfiguration().withDisablePasswordAuthentication(true)
.withSsh(new SshConfiguration().withPublicKeys(
Arrays.asList(new SshPublicKey().withPath("/home/{your-username}/.ssh/authorized_keys")
.withKeyData("fakeTokenPlaceholder"))))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_with_ssh_authentication.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"linuxConfiguration": {
"disablePasswordAuthentication": True,
"ssh": {
"publicKeys": [
{
"keyData": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCeClRAk2ipUs/l5voIsDC5q9RI+YSRd1Bvd/O+axgY4WiBzG+4FwJWZm/mLLe5DoOdHQwmU2FrKXZSW4w2sYE70KeWnrFViCOX5MTVvJgPE8ClugNl8RWth/tU849DvM9sT7vFgfVSHcAS2yDRyDlueii+8nF2ym8XWAPltFVCyLHRsyBp5YPqK8JFYIa1eybKsY3hEAxRCA+/7bq8et+Gj3coOsuRmrehav7rE6N12Pb80I6ofa6SM5XNYq4Xk0iYNx7R3kdz0Jj9XgZYWjAHjJmT0gTRoOnt6upOuxK7xI/ykWrllgpXrCPu3Ymz+c+ujaqcxDopnAl2lmf69/J1",
"path": "/home/{your-username}/.ssh/authorized_keys",
}
]
},
},
},
"storageProfile": {
"imageReference": {
"offer": "{image_offer}",
"publisher": "{image_publisher}",
"sku": "{image_sku}",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithSshAuthentication.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithSshAuthentication.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMWithSshAuthentication() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("{image_sku}"),
Publisher: to.Ptr("{image_publisher}"),
Version: to.Ptr("latest"),
Offer: to.Ptr("{image_offer}"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
Name: to.Ptr("myVMosdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
LinuxConfiguration: &armcompute.LinuxConfiguration{
SSH: &armcompute.SSHConfiguration{
PublicKeys: []*armcompute.SSHPublicKey{
{
Path: to.Ptr("/home/{your-username}/.ssh/authorized_keys"),
KeyData: to.Ptr("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCeClRAk2ipUs/l5voIsDC5q9RI+YSRd1Bvd/O+axgY4WiBzG+4FwJWZm/mLLe5DoOdHQwmU2FrKXZSW4w2sYE70KeWnrFViCOX5MTVvJgPE8ClugNl8RWth/tU849DvM9sT7vFgfVSHcAS2yDRyDlueii+8nF2ym8XWAPltFVCyLHRsyBp5YPqK8JFYIa1eybKsY3hEAxRCA+/7bq8et+Gj3coOsuRmrehav7rE6N12Pb80I6ofa6SM5XNYq4Xk0iYNx7R3kdz0Jj9XgZYWjAHjJmT0gTRoOnt6upOuxK7xI/ykWrllgpXrCPu3Ymz+c+ujaqcxDopnAl2lmf69/J1"),
},
},
},
DisablePasswordAuthentication: to.Ptr(true),
},
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// LinuxConfiguration: &armcompute.LinuxConfiguration{
// SSH: &armcompute.SSHConfiguration{
// PublicKeys: []*armcompute.SSHPublicKey{
// {
// Path: to.Ptr("/home/{your-username}/.ssh/authorized_keys"),
// KeyData: to.Ptr("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCeClRAk2ipUs/l5voIsDC5q9RI+YSRd1Bvd/O+axgY4WiBzG+4FwJWZm/mLLe5DoOdHQwmU2FrKXZSW4w2sYE70KeWnrFViCOX5MTVvJgPE8ClugNl8RWth/tU849DvM9sT7vFgfVSHcAS2yDRyDlueii+8nF2ym8XWAPltFVCyLHRsyBp5YPqK8JFYIa1eybKsY3hEAxRCA+/7bq8et+Gj3coOsuRmrehav7rE6N12Pb80I6ofa6SM5XNYq4Xk0iYNx7R3kdz0Jj9XgZYWjAHjJmT0gTRoOnt6upOuxK7xI/ykWrllgpXrCPu3Ymz+c+ujaqcxDopnAl2lmf69/J1"),
// },
// },
// },
// DisablePasswordAuthentication: to.Ptr(true),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("16.04-LTS"),
// Publisher: to.Ptr("Canonical"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("UbuntuServer"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// VMID: to.Ptr("e0de9b84-a506-4b95-9623-00a425d05c90"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Name: to.Ptr("myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithSshAuthentication.json
*/
async function createAVmWithSshAuthentication() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D1_v2" },
storageProfile: {
imageReference: {
sku: "{image_sku}",
publisher: "{image_publisher}",
version: "latest",
offer: "{image_offer}",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Standard_LRS" },
name: "myVMosdisk",
createOption: "FromImage",
},
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
linuxConfiguration: {
ssh: {
publicKeys: [
{
path: "/home/{your-username}/.ssh/authorized_keys",
keyData:
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCeClRAk2ipUs/l5voIsDC5q9RI+YSRd1Bvd/O+axgY4WiBzG+4FwJWZm/mLLe5DoOdHQwmU2FrKXZSW4w2sYE70KeWnrFViCOX5MTVvJgPE8ClugNl8RWth/tU849DvM9sT7vFgfVSHcAS2yDRyDlueii+8nF2ym8XWAPltFVCyLHRsyBp5YPqK8JFYIa1eybKsY3hEAxRCA+/7bq8et+Gj3coOsuRmrehav7rE6N12Pb80I6ofa6SM5XNYq4Xk0iYNx7R3kdz0Jj9XgZYWjAHjJmT0gTRoOnt6upOuxK7xI/ykWrllgpXrCPu3Ymz+c+ujaqcxDopnAl2lmf69/J1",
},
],
},
disablePasswordAuthentication: true,
},
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"ssh": {
"publicKeys": [
{
"path": "/home/{your-username}/.ssh/authorized_keys",
"keyData": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCeClRAk2ipUs/l5voIsDC5q9RI+YSRd1Bvd/O+axgY4WiBzG+4FwJWZm/mLLe5DoOdHQwmU2FrKXZSW4w2sYE70KeWnrFViCOX5MTVvJgPE8ClugNl8RWth/tU849DvM9sT7vFgfVSHcAS2yDRyDlueii+8nF2ym8XWAPltFVCyLHRsyBp5YPqK8JFYIa1eybKsY3hEAxRCA+/7bq8et+Gj3coOsuRmrehav7rE6N12Pb80I6ofa6SM5XNYq4Xk0iYNx7R3kdz0Jj9XgZYWjAHjJmT0gTRoOnt6upOuxK7xI/ykWrllgpXrCPu3Ymz+c+ujaqcxDopnAl2lmf69/J1"
}
]
},
"disablePasswordAuthentication": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "16.04-LTS",
"publisher": "Canonical",
"version": "latest",
"offer": "UbuntuServer"
},
"osDisk": {
"osType": "Linux",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"vmId": "e0de9b84-a506-4b95-9623-00a425d05c90",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"ssh": {
"publicKeys": [
{
"path": "/home/{your-username}/.ssh/authorized_keys",
"keyData": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCeClRAk2ipUs/l5voIsDC5q9RI+YSRd1Bvd/O+axgY4WiBzG+4FwJWZm/mLLe5DoOdHQwmU2FrKXZSW4w2sYE70KeWnrFViCOX5MTVvJgPE8ClugNl8RWth/tU849DvM9sT7vFgfVSHcAS2yDRyDlueii+8nF2ym8XWAPltFVCyLHRsyBp5YPqK8JFYIa1eybKsY3hEAxRCA+/7bq8et+Gj3coOsuRmrehav7rE6N12Pb80I6ofa6SM5XNYq4Xk0iYNx7R3kdz0Jj9XgZYWjAHjJmT0gTRoOnt6upOuxK7xI/ykWrllgpXrCPu3Ymz+c+ujaqcxDopnAl2lmf69/J1"
}
]
},
"disablePasswordAuthentication": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "16.04-LTS",
"publisher": "Canonical",
"version": "latest",
"offer": "UbuntuServer"
},
"osDisk": {
"osType": "Linux",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"vmId": "e0de9b84-a506-4b95-9623-00a425d05c90",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a VM with Uefi Settings of secureBoot and vTPM.
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"securityProfile": {
"uefiSettings": {
"secureBootEnabled": true,
"vTpmEnabled": true
},
"securityType": "TrustedLaunch"
},
"storageProfile": {
"imageReference": {
"sku": "windows10-tvm",
"publisher": "MicrosoftWindowsServer",
"version": "18363.592.2001092016",
"offer": "windowsserver-gen2preview-preview"
},
"osDisk": {
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "StandardSSD_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.SecurityProfile;
import com.azure.resourcemanager.compute.models.SecurityTypes;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.UefiSettings;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithUefiSettings.json
*/
/**
* Sample code: Create a VM with Uefi Settings of secureBoot and vTPM.
*
* @param manager Entry point to ComputeManager.
*/
public static void
createAVMWithUefiSettingsOfSecureBootAndVTPM(com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference()
.withPublisher("MicrosoftWindowsServer").withOffer("windowsserver-gen2preview-preview")
.withSku("windows10-tvm").withVersion("18363.592.2001092016"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS))))
.withOsProfile(new OSProfile()
.withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withUefiSettings(new UefiSettings().withSecureBootEnabled(true).withVTpmEnabled(true))
.withSecurityType(SecurityTypes.TRUSTED_LAUNCH)),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_with_uefi_settings.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D2s_v3"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"securityProfile": {
"securityType": "TrustedLaunch",
"uefiSettings": {"secureBootEnabled": True, "vTpmEnabled": True},
},
"storageProfile": {
"imageReference": {
"offer": "windowsserver-gen2preview-preview",
"publisher": "MicrosoftWindowsServer",
"sku": "windows10-tvm",
"version": "18363.592.2001092016",
},
"osDisk": {
"caching": "ReadOnly",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "StandardSSD_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithUefiSettings.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithUefiSettings.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMWithUefiSettingsOfSecureBootAndVTpm() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2SV3),
},
SecurityProfile: &armcompute.SecurityProfile{
UefiSettings: &armcompute.UefiSettings{
SecureBootEnabled: to.Ptr(true),
VTpmEnabled: to.Ptr(true),
},
SecurityType: to.Ptr(armcompute.SecurityTypesTrustedLaunch),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("windows10-tvm"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
Version: to.Ptr("18363.592.2001092016"),
Offer: to.Ptr("windowsserver-gen2preview-preview"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadOnly),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardSSDLRS),
},
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
Name: to.Ptr("myVMosdisk"),
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("windows10-tvm"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// Version: to.Ptr("18363.592.2001092016"),
// Offer: to.Ptr("windowsserver-gen2preview-preview"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadOnly),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardSSDLRS),
// },
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// SecurityProfile: &armcompute.SecurityProfile{
// UefiSettings: &armcompute.UefiSettings{
// SecureBootEnabled: to.Ptr(true),
// VTpmEnabled: to.Ptr(true),
// },
// SecurityType: to.Ptr(armcompute.SecurityTypesTrustedLaunch),
// },
// VMID: to.Ptr("5c0d55a7-c407-4ed6-bf7d-ddb810267c85"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2SV3),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithUefiSettings.json
*/
async function createAVMWithUefiSettingsOfSecureBootAndVTPM() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D2s_v3" },
securityProfile: {
uefiSettings: { secureBootEnabled: true, vTpmEnabled: true },
securityType: "TrustedLaunch",
},
storageProfile: {
imageReference: {
sku: "windows10-tvm",
publisher: "MicrosoftWindowsServer",
version: "18363.592.2001092016",
offer: "windowsserver-gen2preview-preview",
},
osDisk: {
caching: "ReadOnly",
managedDisk: { storageAccountType: "StandardSSD_LRS" },
createOption: "FromImage",
name: "myVMosdisk",
},
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "windows10-tvm",
"publisher": "MicrosoftWindowsServer",
"version": "18363.592.2001092016",
"offer": "windowsserver-gen2preview-preview"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "StandardSSD_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"securityProfile": {
"uefiSettings": {
"secureBootEnabled": true,
"vTpmEnabled": true
},
"securityType": "TrustedLaunch"
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "windows10-tvm",
"publisher": "MicrosoftWindowsServer",
"version": "18363.592.2001092016",
"offer": "windowsserver-gen2preview-preview"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "StandardSSD_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"securityProfile": {
"uefiSettings": {
"secureBootEnabled": true,
"vTpmEnabled": true
},
"securityType": "TrustedLaunch"
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
Create a VM with UserData
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/{vm-name}?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "vmOSdisk",
"createOption": "FromImage"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "{vm-name}",
"adminPassword": "{your-password}"
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://{existing-storage-account-name}.blob.core.windows.net",
"enabled": true
}
},
"userData": "RXhhbXBsZSBVc2VyRGF0YQ=="
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.BootDiagnostics;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiagnosticsProfile;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithUserData.json
*/
/**
* Sample code: Create a VM with UserData.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAVMWithUserData(com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "{vm-name}",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("vmOSdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("{vm-name}").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withUserData("RXhhbXBsZSBVc2VyRGF0YQ=="),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_with_user_data.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="{vm-name}",
parameters={
"location": "westus",
"properties": {
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": True,
"storageUri": "http://{existing-storage-account-name}.blob.core.windows.net",
}
},
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "{vm-name}",
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "vmOSdisk",
},
},
"userData": "RXhhbXBsZSBVc2VyRGF0YQ==",
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithUserData.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithUserData.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMWithUserData() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "{vm-name}", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("2016-Datacenter"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
Version: to.Ptr("latest"),
Offer: to.Ptr("WindowsServer"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
Name: to.Ptr("vmOSdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("{vm-name}"),
AdminPassword: to.Ptr("{your-password}"),
},
DiagnosticsProfile: &armcompute.DiagnosticsProfile{
BootDiagnostics: &armcompute.BootDiagnostics{
StorageURI: to.Ptr("http://{existing-storage-account-name}.blob.core.windows.net"),
Enabled: to.Ptr(true),
},
},
UserData: to.Ptr("RXhhbXBsZSBVc2VyRGF0YQ=="),
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/{vm-name}"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("{vm-name}"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("2016-Datacenter"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("WindowsServer"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("vmOSdisk"),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// DiagnosticsProfile: &armcompute.DiagnosticsProfile{
// BootDiagnostics: &armcompute.BootDiagnostics{
// StorageURI: to.Ptr("http://nsgdiagnostic.blob.core.windows.net"),
// Enabled: to.Ptr(true),
// },
// },
// VMID: to.Ptr("676420ba-7a24-4bfe-80bd-9c841ee184fa"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Name: to.Ptr("{vm-name}"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithUserData.json
*/
async function createAVMWithUserData() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "{vm-name}", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D1_v2" },
storageProfile: {
imageReference: {
sku: "2016-Datacenter",
publisher: "MicrosoftWindowsServer",
version: "latest",
offer: "WindowsServer",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Standard_LRS" },
name: "vmOSdisk",
createOption: "FromImage",
},
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminUsername: "{your-username}",
computerName: "{vm-name}",
adminPassword: "{your-password}",
},
diagnosticsProfile: {
bootDiagnostics: {
storageUri: "http://{existing-storage-account-name}.blob.core.windows.net",
enabled: true,
},
},
userData: "RXhhbXBsZSBVc2VyRGF0YQ==",
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/{vm-name}",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "{vm-name}",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "vmOSdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://nsgdiagnostic.blob.core.windows.net",
"enabled": true
}
},
"vmId": "676420ba-7a24-4bfe-80bd-9c841ee184fa",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "{vm-name}",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/{vm-name}",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "{vm-name}",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "vmOSdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://nsgdiagnostic.blob.core.windows.net",
"enabled": true
}
},
"vmId": "676420ba-7a24-4bfe-80bd-9c841ee184fa",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "{vm-name}",
"location": "westus"
}
Create a VM with VM Size Properties
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D4_v3",
"vmSizeProperties": {
"vCPUsAvailable": 1,
"vCPUsPerCore": 1
}
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://{existing-storage-account-name}.blob.core.windows.net",
"enabled": true
}
},
"userData": "U29tZSBDdXN0b20gRGF0YQ=="
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.BootDiagnostics;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiagnosticsProfile;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VMSizeProperties;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithVMSizeProperties.json
*/
/**
* Sample code: Create a VM with VM Size Properties.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAVMWithVMSizeProperties(com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines()
.createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D4_V3)
.withVmSizeProperties(new VMSizeProperties().withVCpusAvailable(1).withVCpusPerCore(1)))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(
new OSProfile()
.withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(
new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics().withEnabled(true)
.withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withUserData("U29tZSBDdXN0b20gRGF0YQ=="),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_with_vm_size_properties.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": True,
"storageUri": "http://{existing-storage-account-name}.blob.core.windows.net",
}
},
"hardwareProfile": {
"vmSize": "Standard_D4_v3",
"vmSizeProperties": {"vCPUsAvailable": 1, "vCPUsPerCore": 1},
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
"userData": "U29tZSBDdXN0b20gRGF0YQ==",
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithVMSizeProperties.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithVMSizeProperties.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVMWithVMSizeProperties() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD4V3),
VMSizeProperties: &armcompute.VMSizeProperties{
VCPUsAvailable: to.Ptr[int32](1),
VCPUsPerCore: to.Ptr[int32](1),
},
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("2016-Datacenter"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
Version: to.Ptr("latest"),
Offer: to.Ptr("WindowsServer"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
Name: to.Ptr("myVMosdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
DiagnosticsProfile: &armcompute.DiagnosticsProfile{
BootDiagnostics: &armcompute.BootDiagnostics{
StorageURI: to.Ptr("http://{existing-storage-account-name}.blob.core.windows.net"),
Enabled: to.Ptr(true),
},
},
UserData: to.Ptr("U29tZSBDdXN0b20gRGF0YQ=="),
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("2016-Datacenter"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("WindowsServer"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// DiagnosticsProfile: &armcompute.DiagnosticsProfile{
// BootDiagnostics: &armcompute.BootDiagnostics{
// StorageURI: to.Ptr("http://nsgdiagnostic.blob.core.windows.net"),
// Enabled: to.Ptr(true),
// },
// },
// VMID: to.Ptr("676420ba-7a24-4bfe-80bd-9c841ee184fa"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD4V3),
// VMSizeProperties: &armcompute.VMSizeProperties{
// VCPUsAvailable: to.Ptr[int32](1),
// VCPUsPerCore: to.Ptr[int32](1),
// },
// },
// ProvisioningState: to.Ptr("Updating"),
// },
// Name: to.Ptr("myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithVMSizeProperties.json
*/
async function createAVMWithVMSizeProperties() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: {
vmSize: "Standard_D4_v3",
vmSizeProperties: { vCPUsAvailable: 1, vCPUsPerCore: 1 },
},
storageProfile: {
imageReference: {
sku: "2016-Datacenter",
publisher: "MicrosoftWindowsServer",
version: "latest",
offer: "WindowsServer",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Standard_LRS" },
name: "myVMosdisk",
createOption: "FromImage",
},
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
diagnosticsProfile: {
bootDiagnostics: {
storageUri: "http://{existing-storage-account-name}.blob.core.windows.net",
enabled: true,
},
},
userData: "U29tZSBDdXN0b20gRGF0YQ==",
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://nsgdiagnostic.blob.core.windows.net",
"enabled": true
}
},
"vmId": "676420ba-7a24-4bfe-80bd-9c841ee184fa",
"hardwareProfile": {
"vmSize": "Standard_D4_v3",
"vmSizeProperties": {
"vCPUsAvailable": 1,
"vCPUsPerCore": 1
}
},
"provisioningState": "Updating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://nsgdiagnostic.blob.core.windows.net",
"enabled": true
}
},
"vmId": "676420ba-7a24-4bfe-80bd-9c841ee184fa",
"hardwareProfile": {
"vmSize": "Standard_D4_v3",
"vmSizeProperties": {
"vCPUsAvailable": 1,
"vCPUsPerCore": 1
}
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a Windows vm with a patch setting assessmentMode of ImageDefault.
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Premium_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true,
"patchSettings": {
"assessmentMode": "ImageDefault"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.PatchSettings;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import com.azure.resourcemanager.compute.models.WindowsConfiguration;
import com.azure.resourcemanager.compute.models.WindowsPatchAssessmentMode;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingAssessmentModeOfImageDefault.
* json
*/
/**
* Sample code: Create a Windows vm with a patch setting assessmentMode of ImageDefault.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAWindowsVmWithAPatchSettingAssessmentModeOfImageDefault(
com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withWindowsConfiguration(new WindowsConfiguration().withProvisionVMAgent(true)
.withEnableAutomaticUpdates(true).withPatchSettings(
new PatchSettings().withAssessmentMode(WindowsPatchAssessmentMode.IMAGE_DEFAULT))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_windows_vm_with_patch_setting_assessment_mode_of_image_default.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
"windowsConfiguration": {
"enableAutomaticUpdates": True,
"patchSettings": {"assessmentMode": "ImageDefault"},
"provisionVMAgent": True,
},
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Premium_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingAssessmentModeOfImageDefault.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingAssessmentModeOfImageDefault.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAWindowsVMWithAPatchSettingAssessmentModeOfImageDefault() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("2016-Datacenter"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
Version: to.Ptr("latest"),
Offer: to.Ptr("WindowsServer"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
},
Name: to.Ptr("myVMosdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
WindowsConfiguration: &armcompute.WindowsConfiguration{
ProvisionVMAgent: to.Ptr(true),
EnableAutomaticUpdates: to.Ptr(true),
PatchSettings: &armcompute.PatchSettings{
AssessmentMode: to.Ptr(armcompute.WindowsPatchAssessmentModeImageDefault),
},
},
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// PatchSettings: &armcompute.PatchSettings{
// AssessmentMode: to.Ptr(armcompute.WindowsPatchAssessmentModeImageDefault),
// },
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("2016-Datacenter"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("WindowsServer"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
// },
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// VMID: to.Ptr("a149cd25-409f-41af-8088-275f5486bc93"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Name: to.Ptr("myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingAssessmentModeOfImageDefault.json
*/
async function createAWindowsVmWithAPatchSettingAssessmentModeOfImageDefault() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D1_v2" },
storageProfile: {
imageReference: {
sku: "2016-Datacenter",
publisher: "MicrosoftWindowsServer",
version: "latest",
offer: "WindowsServer",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Premium_LRS" },
name: "myVMosdisk",
createOption: "FromImage",
},
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
windowsConfiguration: {
provisionVMAgent: true,
enableAutomaticUpdates: true,
patchSettings: { assessmentMode: "ImageDefault" },
},
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true,
"patchSettings": {
"assessmentMode": "ImageDefault"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": false,
"patchSettings": {
"assessmentMode": "ImageDefault"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a Windows vm with a patch setting patchMode of AutomaticByOS.
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Premium_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true,
"patchSettings": {
"patchMode": "AutomaticByOS"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.PatchSettings;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import com.azure.resourcemanager.compute.models.WindowsConfiguration;
import com.azure.resourcemanager.compute.models.WindowsVMGuestPatchMode;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingModeOfAutomaticByOS.json
*/
/**
* Sample code: Create a Windows vm with a patch setting patchMode of AutomaticByOS.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAWindowsVmWithAPatchSettingPatchModeOfAutomaticByOS(
com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withWindowsConfiguration(new WindowsConfiguration().withProvisionVMAgent(true)
.withEnableAutomaticUpdates(true)
.withPatchSettings(new PatchSettings().withPatchMode(WindowsVMGuestPatchMode.AUTOMATIC_BY_OS))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_windows_vm_with_patch_setting_mode_of_automatic_by_os.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
"windowsConfiguration": {
"enableAutomaticUpdates": True,
"patchSettings": {"patchMode": "AutomaticByOS"},
"provisionVMAgent": True,
},
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Premium_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingModeOfAutomaticByOS.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingModeOfAutomaticByOS.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAWindowsVMWithAPatchSettingPatchModeOfAutomaticByOS() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("2016-Datacenter"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
Version: to.Ptr("latest"),
Offer: to.Ptr("WindowsServer"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
},
Name: to.Ptr("myVMosdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
WindowsConfiguration: &armcompute.WindowsConfiguration{
ProvisionVMAgent: to.Ptr(true),
EnableAutomaticUpdates: to.Ptr(true),
PatchSettings: &armcompute.PatchSettings{
PatchMode: to.Ptr(armcompute.WindowsVMGuestPatchModeAutomaticByOS),
},
},
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// PatchSettings: &armcompute.PatchSettings{
// PatchMode: to.Ptr(armcompute.WindowsVMGuestPatchModeAutomaticByOS),
// },
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("2016-Datacenter"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("WindowsServer"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
// },
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// VMID: to.Ptr("a149cd25-409f-41af-8088-275f5486bc93"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Name: to.Ptr("myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingModeOfAutomaticByOS.json
*/
async function createAWindowsVmWithAPatchSettingPatchModeOfAutomaticByOS() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D1_v2" },
storageProfile: {
imageReference: {
sku: "2016-Datacenter",
publisher: "MicrosoftWindowsServer",
version: "latest",
offer: "WindowsServer",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Premium_LRS" },
name: "myVMosdisk",
createOption: "FromImage",
},
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
windowsConfiguration: {
provisionVMAgent: true,
enableAutomaticUpdates: true,
patchSettings: { patchMode: "AutomaticByOS" },
},
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true,
"patchSettings": {
"patchMode": "AutomaticByOS"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true,
"patchSettings": {
"patchMode": "AutomaticByOS"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Premium_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true,
"patchSettings": {
"patchMode": "AutomaticByPlatform",
"assessmentMode": "AutomaticByPlatform",
"automaticByPlatformSettings": {
"rebootSetting": "Never",
"bypassPlatformSafetyChecksOnUserSchedule": false
}
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.PatchSettings;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import com.azure.resourcemanager.compute.models.WindowsConfiguration;
import com.azure.resourcemanager.compute.models.WindowsPatchAssessmentMode;
import com.azure.resourcemanager.compute.models.WindowsVMGuestPatchAutomaticByPlatformRebootSetting;
import com.azure.resourcemanager.compute.models.WindowsVMGuestPatchAutomaticByPlatformSettings;
import com.azure.resourcemanager.compute.models.WindowsVMGuestPatchMode;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithAutomaticByPlatformSettings.json
*/
/**
* Sample code: Create a Windows vm with a patch setting patchMode of AutomaticByPlatform and
* AutomaticByPlatformSettings.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAWindowsVmWithAPatchSettingPatchModeOfAutomaticByPlatformAndAutomaticByPlatformSettings(
com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(
new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder").withWindowsConfiguration(
new WindowsConfiguration().withProvisionVMAgent(true).withEnableAutomaticUpdates(true)
.withPatchSettings(new PatchSettings()
.withPatchMode(WindowsVMGuestPatchMode.AUTOMATIC_BY_PLATFORM)
.withAssessmentMode(WindowsPatchAssessmentMode.AUTOMATIC_BY_PLATFORM)
.withAutomaticByPlatformSettings(
new WindowsVMGuestPatchAutomaticByPlatformSettings()
.withRebootSetting(WindowsVMGuestPatchAutomaticByPlatformRebootSetting.NEVER)
.withBypassPlatformSafetyChecksOnUserSchedule(false)))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_windows_vm_with_automatic_by_platform_settings.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
"windowsConfiguration": {
"enableAutomaticUpdates": True,
"patchSettings": {
"assessmentMode": "AutomaticByPlatform",
"automaticByPlatformSettings": {
"bypassPlatformSafetyChecksOnUserSchedule": False,
"rebootSetting": "Never",
},
"patchMode": "AutomaticByPlatform",
},
"provisionVMAgent": True,
},
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Premium_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithAutomaticByPlatformSettings.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithAutomaticByPlatformSettings.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAWindowsVMWithAPatchSettingPatchModeOfAutomaticByPlatformAndAutomaticByPlatformSettings() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("2016-Datacenter"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
Version: to.Ptr("latest"),
Offer: to.Ptr("WindowsServer"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
},
Name: to.Ptr("myVMosdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
WindowsConfiguration: &armcompute.WindowsConfiguration{
ProvisionVMAgent: to.Ptr(true),
EnableAutomaticUpdates: to.Ptr(true),
PatchSettings: &armcompute.PatchSettings{
PatchMode: to.Ptr(armcompute.WindowsVMGuestPatchModeAutomaticByPlatform),
AssessmentMode: to.Ptr(armcompute.WindowsPatchAssessmentModeAutomaticByPlatform),
AutomaticByPlatformSettings: &armcompute.WindowsVMGuestPatchAutomaticByPlatformSettings{
RebootSetting: to.Ptr(armcompute.WindowsVMGuestPatchAutomaticByPlatformRebootSettingNever),
BypassPlatformSafetyChecksOnUserSchedule: to.Ptr(false),
},
},
},
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// PatchSettings: &armcompute.PatchSettings{
// PatchMode: to.Ptr(armcompute.WindowsVMGuestPatchModeAutomaticByPlatform),
// AssessmentMode: to.Ptr(armcompute.WindowsPatchAssessmentModeAutomaticByPlatform),
// AutomaticByPlatformSettings: &armcompute.WindowsVMGuestPatchAutomaticByPlatformSettings{
// RebootSetting: to.Ptr(armcompute.WindowsVMGuestPatchAutomaticByPlatformRebootSettingNever),
// BypassPlatformSafetyChecksOnUserSchedule: to.Ptr(false),
// },
// },
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("2016-Datacenter"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("WindowsServer"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
// },
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// VMID: to.Ptr("a149cd25-409f-41af-8088-275f5486bc93"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Name: to.Ptr("myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithAutomaticByPlatformSettings.json
*/
async function createAWindowsVmWithAPatchSettingPatchModeOfAutomaticByPlatformAndAutomaticByPlatformSettings() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D1_v2" },
storageProfile: {
imageReference: {
sku: "2016-Datacenter",
publisher: "MicrosoftWindowsServer",
version: "latest",
offer: "WindowsServer",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Premium_LRS" },
name: "myVMosdisk",
createOption: "FromImage",
},
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
windowsConfiguration: {
provisionVMAgent: true,
enableAutomaticUpdates: true,
patchSettings: {
patchMode: "AutomaticByPlatform",
assessmentMode: "AutomaticByPlatform",
automaticByPlatformSettings: {
rebootSetting: "Never",
bypassPlatformSafetyChecksOnUserSchedule: false,
},
},
},
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true,
"patchSettings": {
"patchMode": "AutomaticByPlatform",
"assessmentMode": "AutomaticByPlatform",
"automaticByPlatformSettings": {
"rebootSetting": "Never",
"bypassPlatformSafetyChecksOnUserSchedule": false
}
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true,
"patchSettings": {
"patchMode": "AutomaticByPlatform",
"assessmentMode": "AutomaticByPlatform",
"automaticByPlatformSettings": {
"rebootSetting": "Never",
"bypassPlatformSafetyChecksOnUserSchedule": false
}
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Premium_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true,
"patchSettings": {
"patchMode": "AutomaticByPlatform",
"enableHotpatching": true
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.PatchSettings;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import com.azure.resourcemanager.compute.models.WindowsConfiguration;
import com.azure.resourcemanager.compute.models.WindowsVMGuestPatchMode;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-04-01/virtualMachineExamples/
* VirtualMachine_Create_WindowsVmWithPatchSettingModeOfAutomaticByPlatformAndEnableHotPatchingTrue.json
*/
/**
* Sample code: Create a Windows vm with a patch setting patchMode of AutomaticByPlatform and enableHotpatching set
* to true.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAWindowsVmWithAPatchSettingPatchModeOfAutomaticByPlatformAndEnableHotpatchingSetToTrue(
com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withWindowsConfiguration(new WindowsConfiguration().withProvisionVMAgent(true)
.withEnableAutomaticUpdates(true)
.withPatchSettings(
new PatchSettings()
.withPatchMode(WindowsVMGuestPatchMode.AUTOMATIC_BY_PLATFORM)
.withEnableHotpatching(true))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_windows_vm_with_patch_setting_mode_of_automatic_by_platform_and_enable_hot_patching_true.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
"windowsConfiguration": {
"enableAutomaticUpdates": True,
"patchSettings": {"enableHotpatching": True, "patchMode": "AutomaticByPlatform"},
"provisionVMAgent": True,
},
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Premium_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingModeOfAutomaticByPlatformAndEnableHotPatchingTrue.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingModeOfAutomaticByPlatformAndEnableHotPatchingTrue.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAWindowsVMWithAPatchSettingPatchModeOfAutomaticByPlatformAndEnableHotpatchingSetToTrue() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("2016-Datacenter"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
Version: to.Ptr("latest"),
Offer: to.Ptr("WindowsServer"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
},
Name: to.Ptr("myVMosdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
WindowsConfiguration: &armcompute.WindowsConfiguration{
ProvisionVMAgent: to.Ptr(true),
EnableAutomaticUpdates: to.Ptr(true),
PatchSettings: &armcompute.PatchSettings{
PatchMode: to.Ptr(armcompute.WindowsVMGuestPatchModeAutomaticByPlatform),
EnableHotpatching: to.Ptr(true),
},
},
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// PatchSettings: &armcompute.PatchSettings{
// PatchMode: to.Ptr(armcompute.WindowsVMGuestPatchModeAutomaticByPlatform),
// EnableHotpatching: to.Ptr(true),
// },
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("2016-Datacenter"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("WindowsServer"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
// },
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// VMID: to.Ptr("a149cd25-409f-41af-8088-275f5486bc93"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Name: to.Ptr("myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingModeOfAutomaticByPlatformAndEnableHotPatchingTrue.json
*/
async function createAWindowsVmWithAPatchSettingPatchModeOfAutomaticByPlatformAndEnableHotpatchingSetToTrue() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D1_v2" },
storageProfile: {
imageReference: {
sku: "2016-Datacenter",
publisher: "MicrosoftWindowsServer",
version: "latest",
offer: "WindowsServer",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Premium_LRS" },
name: "myVMosdisk",
createOption: "FromImage",
},
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
windowsConfiguration: {
provisionVMAgent: true,
enableAutomaticUpdates: true,
patchSettings: { patchMode: "AutomaticByPlatform", enableHotpatching: true },
},
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true,
"patchSettings": {
"patchMode": "AutomaticByPlatform",
"enableHotpatching": true
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true,
"patchSettings": {
"patchMode": "AutomaticByPlatform",
"enableHotpatching": true
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a Windows vm with a patch setting patchMode of Manual.
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Premium_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true,
"patchSettings": {
"patchMode": "Manual"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.PatchSettings;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import com.azure.resourcemanager.compute.models.WindowsConfiguration;
import com.azure.resourcemanager.compute.models.WindowsVMGuestPatchMode;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingModeOfManual.json
*/
/**
* Sample code: Create a Windows vm with a patch setting patchMode of Manual.
*
* @param manager Entry point to ComputeManager.
*/
public static void
createAWindowsVmWithAPatchSettingPatchModeOfManual(com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(
new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withWindowsConfiguration(new WindowsConfiguration()
.withProvisionVMAgent(true).withEnableAutomaticUpdates(true)
.withPatchSettings(new PatchSettings().withPatchMode(WindowsVMGuestPatchMode.MANUAL))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_windows_vm_with_patch_setting_mode_of_manual.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
"windowsConfiguration": {
"enableAutomaticUpdates": True,
"patchSettings": {"patchMode": "Manual"},
"provisionVMAgent": True,
},
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Premium_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingModeOfManual.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingModeOfManual.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAWindowsVMWithAPatchSettingPatchModeOfManual() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("2016-Datacenter"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
Version: to.Ptr("latest"),
Offer: to.Ptr("WindowsServer"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
},
Name: to.Ptr("myVMosdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
WindowsConfiguration: &armcompute.WindowsConfiguration{
ProvisionVMAgent: to.Ptr(true),
EnableAutomaticUpdates: to.Ptr(true),
PatchSettings: &armcompute.PatchSettings{
PatchMode: to.Ptr(armcompute.WindowsVMGuestPatchModeManual),
},
},
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// PatchSettings: &armcompute.PatchSettings{
// PatchMode: to.Ptr(armcompute.WindowsVMGuestPatchModeManual),
// },
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("2016-Datacenter"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("WindowsServer"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
// },
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// VMID: to.Ptr("a149cd25-409f-41af-8088-275f5486bc93"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Name: to.Ptr("myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingModeOfManual.json
*/
async function createAWindowsVmWithAPatchSettingPatchModeOfManual() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D1_v2" },
storageProfile: {
imageReference: {
sku: "2016-Datacenter",
publisher: "MicrosoftWindowsServer",
version: "latest",
offer: "WindowsServer",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Premium_LRS" },
name: "myVMosdisk",
createOption: "FromImage",
},
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
windowsConfiguration: {
provisionVMAgent: true,
enableAutomaticUpdates: true,
patchSettings: { patchMode: "Manual" },
},
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true,
"patchSettings": {
"patchMode": "Manual"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": false,
"patchSettings": {
"patchMode": "Manual"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Premium_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true,
"patchSettings": {
"patchMode": "AutomaticByPlatform",
"assessmentMode": "AutomaticByPlatform"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.PatchSettings;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import com.azure.resourcemanager.compute.models.WindowsConfiguration;
import com.azure.resourcemanager.compute.models.WindowsPatchAssessmentMode;
import com.azure.resourcemanager.compute.models.WindowsVMGuestPatchMode;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingModesOfAutomaticByPlatform.json
*/
/**
* Sample code: Create a Windows vm with patch settings patchMode and assessmentMode set to AutomaticByPlatform.
*
* @param manager Entry point to ComputeManager.
*/
public static void createAWindowsVmWithPatchSettingsPatchModeAndAssessmentModeSetToAutomaticByPlatform(
com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(
new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(
new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder").withWindowsConfiguration(
new WindowsConfiguration().withProvisionVMAgent(true).withEnableAutomaticUpdates(true)
.withPatchSettings(new PatchSettings()
.withPatchMode(WindowsVMGuestPatchMode.AUTOMATIC_BY_PLATFORM)
.withAssessmentMode(WindowsPatchAssessmentMode.AUTOMATIC_BY_PLATFORM))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_windows_vm_with_patch_setting_modes_of_automatic_by_platform.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
"windowsConfiguration": {
"enableAutomaticUpdates": True,
"patchSettings": {"assessmentMode": "AutomaticByPlatform", "patchMode": "AutomaticByPlatform"},
"provisionVMAgent": True,
},
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Premium_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingModesOfAutomaticByPlatform.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingModesOfAutomaticByPlatform.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAWindowsVMWithPatchSettingsPatchModeAndAssessmentModeSetToAutomaticByPlatform() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("2016-Datacenter"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
Version: to.Ptr("latest"),
Offer: to.Ptr("WindowsServer"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
},
Name: to.Ptr("myVMosdisk"),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
WindowsConfiguration: &armcompute.WindowsConfiguration{
ProvisionVMAgent: to.Ptr(true),
EnableAutomaticUpdates: to.Ptr(true),
PatchSettings: &armcompute.PatchSettings{
PatchMode: to.Ptr(armcompute.WindowsVMGuestPatchModeAutomaticByPlatform),
AssessmentMode: to.Ptr(armcompute.WindowsPatchAssessmentModeAutomaticByPlatform),
},
},
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// PatchSettings: &armcompute.PatchSettings{
// PatchMode: to.Ptr(armcompute.WindowsVMGuestPatchModeAutomaticByPlatform),
// AssessmentMode: to.Ptr(armcompute.WindowsPatchAssessmentModeAutomaticByPlatform),
// },
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("2016-Datacenter"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("WindowsServer"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
// },
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// VMID: to.Ptr("a149cd25-409f-41af-8088-275f5486bc93"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Name: to.Ptr("myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingModesOfAutomaticByPlatform.json
*/
async function createAWindowsVmWithPatchSettingsPatchModeAndAssessmentModeSetToAutomaticByPlatform() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
hardwareProfile: { vmSize: "Standard_D1_v2" },
storageProfile: {
imageReference: {
sku: "2016-Datacenter",
publisher: "MicrosoftWindowsServer",
version: "latest",
offer: "WindowsServer",
},
osDisk: {
caching: "ReadWrite",
managedDisk: { storageAccountType: "Premium_LRS" },
name: "myVMosdisk",
createOption: "FromImage",
},
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
windowsConfiguration: {
provisionVMAgent: true,
enableAutomaticUpdates: true,
patchSettings: { patchMode: "AutomaticByPlatform", assessmentMode: "AutomaticByPlatform" },
},
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true,
"patchSettings": {
"patchMode": "AutomaticByPlatform",
"assessmentMode": "AutomaticByPlatform"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true,
"patchSettings": {
"patchMode": "AutomaticByPlatform",
"assessmentMode": "AutomaticByPlatform"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create or update a VM with capacity reservation
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2026-04-01
{
"location": "westus",
"plan": {
"publisher": "microsoft-ads",
"product": "windows-data-science-vm",
"name": "windows2016"
},
"properties": {
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "windows2016",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "windows-data-science-vm"
},
"osDisk": {
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
}
},
"capacityReservation": {
"capacityReservationGroup": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/CapacityReservationGroups/{crgName}"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
import com.azure.core.management.SubResource;
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.CapacityReservationProfile;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.Plan;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithCapacityReservation.json
*/
/**
* Sample code: Create or update a VM with capacity reservation.
*
* @param manager Entry point to ComputeManager.
*/
public static void
createOrUpdateAVMWithCapacityReservation(com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_DS1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile()
.withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withCapacityReservation(
new CapacityReservationProfile().withCapacityReservationGroup(new SubResource().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/CapacityReservationGroups/{crgName}"))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_create_with_capacity_reservation.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.virtual_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"plan": {"name": "windows2016", "product": "windows-data-science-vm", "publisher": "microsoft-ads"},
"properties": {
"capacityReservation": {
"capacityReservationGroup": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/CapacityReservationGroups/{crgName}"
}
},
"hardwareProfile": {"vmSize": "Standard_DS1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"offer": "windows-data-science-vm",
"publisher": "microsoft-ads",
"sku": "windows2016",
"version": "latest",
},
"osDisk": {
"caching": "ReadOnly",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithCapacityReservation.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithCapacityReservation.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createOrUpdateAVMWithCapacityReservation() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Plan: &armcompute.Plan{
Publisher: to.Ptr("microsoft-ads"),
Product: to.Ptr("windows-data-science-vm"),
Name: to.Ptr("windows2016"),
},
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SKU: to.Ptr("windows2016"),
Publisher: to.Ptr("microsoft-ads"),
Version: to.Ptr("latest"),
Offer: to.Ptr("windows-data-science-vm"),
},
OSDisk: &armcompute.OSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadOnly),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
Name: to.Ptr("myVMosdisk"),
},
},
CapacityReservation: &armcompute.CapacityReservationProfile{
CapacityReservationGroup: &armcompute.SubResource{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/CapacityReservationGroups/{crgName}"),
},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
AdminPassword: to.Ptr("{your-password}"),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
res, err := poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to poll the result: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.VirtualMachinesClientCreateOrUpdateResponse{
// VirtualMachine: armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Properties: &armcompute.VirtualMachineProperties{
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// ComputerName: to.Ptr("myVM"),
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// ProvisionVMAgent: to.Ptr(true),
// EnableAutomaticUpdates: to.Ptr(true),
// },
// },
// CapacityReservation: &armcompute.CapacityReservationProfile{
// CapacityReservationGroup: &armcompute.SubResource{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/CapacityReservationGroups/{crgName}"),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// },
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// ImageReference: &armcompute.ImageReference{
// SKU: to.Ptr("standard-data-science-vm"),
// Publisher: to.Ptr("microsoft-ads"),
// Version: to.Ptr("latest"),
// Offer: to.Ptr("standard-data-science-vm"),
// },
// OSDisk: &armcompute.OSDisk{
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Caching: to.Ptr(armcompute.CachingTypesReadOnly),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Name: to.Ptr("myVMosdisk"),
// },
// DataDisks: []*armcompute.DataDisk{
// },
// },
// VMID: to.Ptr("5c0d55a7-c407-4ed6-bf7d-ddb810267c85"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
// },
// ProvisioningState: to.Ptr("Creating"),
// },
// Plan: &armcompute.Plan{
// Publisher: to.Ptr("microsoft-ads"),
// Product: to.Ptr("standard-data-science-vm"),
// Name: to.Ptr("standard-data-science-vm"),
// },
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary the operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: 2026-04-01/virtualMachineExamples/VirtualMachine_Create_WithCapacityReservation.json
*/
async function createOrUpdateAVMWithCapacityReservation() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.createOrUpdate("myResourceGroup", "myVM", {
location: "westus",
plan: { publisher: "microsoft-ads", product: "windows-data-science-vm", name: "windows2016" },
hardwareProfile: { vmSize: "Standard_DS1_v2" },
storageProfile: {
imageReference: {
sku: "windows2016",
publisher: "microsoft-ads",
version: "latest",
offer: "windows-data-science-vm",
},
osDisk: {
caching: "ReadOnly",
managedDisk: { storageAccountType: "Standard_LRS" },
createOption: "FromImage",
name: "myVMosdisk",
},
},
capacityReservation: {
capacityReservationGroup: {
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/CapacityReservationGroups/{crgName}",
},
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
adminPassword: "{your-password}",
},
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"capacityReservation": {
"capacityReservationGroup": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/CapacityReservationGroups/{crgName}"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "standard-data-science-vm",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "standard-data-science-vm"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"plan": {
"publisher": "microsoft-ads",
"product": "standard-data-science-vm",
"name": "standard-data-science-vm"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"capacityReservation": {
"capacityReservationGroup": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/CapacityReservationGroups/{crgName}"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "standard-data-science-vm",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "standard-data-science-vm"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"plan": {
"publisher": "microsoft-ads",
"product": "standard-data-science-vm",
"name": "standard-data-science-vm"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
Definities
| Name |
Description |
|
AdditionalCapabilities
|
Hiermee schakelt u een mogelijkheid op de virtuele machine of virtuele-machineschaalset in of uit.
|
|
AdditionalDiskProperties
|
Specificeert aanvullende eigenschappen voor een beheerde schijf die kunnen worden ingesteld op het moment van impliciete creatie van de schijf.
|
|
AdditionalUnattendContent
|
Hiermee geeft u aanvullende XML-opgemaakte informatie op die kan worden opgenomen in het Unattend.xml-bestand, dat wordt gebruikt door Windows Setup. De inhoud wordt gedefinieerd door de naam van de instelling, de onderdeelnaam en de pass waarin de inhoud wordt toegepast.
|
|
AllInstancesDown
|
Geeft aan of geplande gebeurtenissen automatisch moeten worden goedgekeurd wanneer alle exemplaren niet beschikbaar zijn.
|
|
ApiEntityReference
|
De API-entiteitsreferentie.
|
|
ApiError
|
Api-fout.
|
|
ApiErrorBase
|
Api-foutbasis.
|
|
ApplicationProfile
|
Bevat de lijst met galerietoepassingen die beschikbaar moeten worden gesteld voor de VM/VMSS
|
|
AvailabilityPolicyDiskDelay
|
Bepaalt hoe schijven met trage I/O moeten worden verwerkt.
|
|
AvailablePatchSummary
|
Beschrijft de eigenschappen van een exemplaarweergave van een virtuele machine voor de beschikbare patchsamenvatting.
|
|
BillingProfile
|
Hiermee geeft u de factureringsgerelateerde details van een Azure Spot-VM of VMSS op. Minimale API-versie: 2019-03-01.
|
|
BootDiagnostics
|
Diagnostische gegevens over opstarten is een functie voor foutopsporing waarmee u console-uitvoer en schermopname kunt bekijken om de VM-status te diagnosticeren. U kunt eenvoudig de uitvoer van uw consolelogboek bekijken. Met Azure kunt u ook een schermopname van de virtuele machine bekijken vanuit de hypervisor.
|
|
BootDiagnosticsInstanceView
|
De exemplaarweergave van diagnostische gegevens over opstarten van virtuele machines.
|
|
CachingTypes
|
Hiermee geeft u de cachevereisten op. Mogelijke waarden zijn: Geen,Alleen-lezen,Lezen'. De standaardwaarden zijn: Geen voor standaardopslag. ReadOnly voor Premium opslag
|
|
CapacityReservationProfile
|
De parameters van een capaciteitsreserveringsprofiel.
|
|
CapacityReservationType
|
Specificeert van welk type capaciteitsreservering de virtuele machine capaciteit zal verbruiken als deze in aanmerking komt, of dat deze expliciet is afgestemd op het gekoppeld zijn en verbruiken van capaciteit uit elke gereserveerde capaciteit die beschikbaar is in het abonnement. Minimale api-versie: 2026-04-01.
|
|
CloudError
|
Een foutreactie van de Compute-service.
|
|
Common.UserAssignedIdentitiesValue
|
|
|
ComponentNames
|
|
|
createdByType
|
Het identiteitstype dat de resource heeft gemaakt.
|
|
DataDisk
|
Beschrijft een gegevensschijf.
|
|
DeleteOptions
|
Opgeven wat er gebeurt met de netwerkinterface wanneer de VIRTUELE machine wordt verwijderd
|
|
DiagnosticsProfile
|
Hiermee geeft u de status van diagnostische instellingen voor opstarten. Minimale API-versie: 2015-06-15.
|
|
DiffDiskOptions
|
Hiermee geeft u de tijdelijke schijfoptie voor de besturingssysteemschijf.
|
|
DiffDiskPlacement
|
Hiermee geeft u de tijdelijke schijfplaatsing voor de besturingssysteemschijf. Deze eigenschap kan worden gebruikt door de gebruiker in de aanvraag om de locatie te kiezen, bijvoorbeeld de cacheschijf, de resourceschijf of de nvme-schijfruimte voor tijdelijke inrichting van besturingssysteemschijven. Voor meer informatie over tijdelijke vereisten voor besturingssysteemschijfgrootte, raadpleegt u kortstondige besturingssysteemschijfgroottevereisten voor Windows-VM op https://docs.microsoft.com/azure/virtual-machines/windows/ephemeral-os-disks#size-requirements en Linux-VM op https://docs.microsoft.com/azure/virtual-machines/linux/ephemeral-os-disks#size-requirements. Minimale API-versie voor NvmeDisk: 2024-03-01.
|
|
DiffDiskSettings
|
Beschrijft de parameters van tijdelijke schijfinstellingen die kunnen worden opgegeven voor de besturingssysteemschijf.
Opmerking: De tijdelijke schijfinstellingen kunnen alleen worden opgegeven voor beheerde schijven.
|
|
DiskApiVersion
|
Specificeert de Disk API-versie die wordt gebruikt bij het toepassen van additionalDiskProperties op beheerde schijven. De waarde moet in het formaat JJJJ-MM-DD zijn.
|
|
DiskAvailabilityPolicy
|
In het geval van een beschikbaarheids- of verbindingsprobleem met de schijf, specificeer dan het gedrag van je VM.
|
|
DiskControllerTypes
|
Hiermee geeft u het type schijfcontroller geconfigureerd voor de VIRTUELE machine en VirtualMachineScaleSet. Deze eigenschap wordt alleen ondersteund voor virtuele machines waarvan de besturingssysteemschijf en de VM-sku ondersteuning biedt voor generatie 2 (https://docs.microsoft.com/en-us/azure/virtual-machines/generation-2), controleert u de HyperVGenerations-functie die wordt geretourneerd als onderdeel van de SKU-mogelijkheden van de VM in het antwoord van de API voor Microsoft.Compute SKU's voor de regio bevat V2 (https://docs.microsoft.com/rest/api/compute/resourceskus/list). Raadpleeg voor meer informatie over ondersteunde https://aka.ms/azure-diskcontrollertypesschijfcontrollertypen.
|
|
DiskCreateOptionTypes
|
Hiermee geeft u op hoe de schijf van de virtuele machine moet worden gemaakt. Mogelijke waarden zijn Koppelen: Deze waarde wordt gebruikt wanneer u een gespecialiseerde schijf gebruikt om de virtuele machine te maken.
FromImage: Deze waarde wordt gebruikt wanneer u een installatiekopie gebruikt om de virtuele machine te maken. Als u een platforminstallatiekopie gebruikt, moet u ook het element imageReference gebruiken dat hierboven wordt beschreven. Als u een marketplace-installatiekopieën gebruikt, moet u ook het eerder beschreven planelement gebruiken.
Leeg: Deze waarde wordt gebruikt bij het maken van een lege gegevensschijf.
Kopiëren: Deze waarde wordt gebruikt om een gegevensschijf te maken op basis van een momentopname of een andere schijf.
Herstellen: Deze waarde wordt gebruikt om een gegevensschijf te maken vanaf een schijfherstelpunt.
|
|
DiskDeleteOptionTypes
|
Hiermee geeft u het gedrag van de beheerde schijf op wanneer de virtuele machine wordt verwijderd, bijvoorbeeld of de beheerde schijf wordt verwijderd of losgekoppeld. Ondersteunde waarden zijn: Verwijderen. Als deze waarde wordt gebruikt, wordt de beheerde schijf verwijderd wanneer de VIRTUELE machine wordt verwijderd. Loskoppelen. Als deze waarde wordt gebruikt, blijft de beheerde schijf behouden nadat de VIRTUELE machine is verwijderd. Minimale API-versie: 2021-03-01.
|
|
DiskDetachOptionTypes
|
Hiermee geeft u het loskoppelgedrag op dat moet worden gebruikt tijdens het loskoppelen van een schijf of die al bezig is met loskoppelen van de virtuele machine. Ondersteunde waarden zijn: ForceDetach. detachOption: ForceDetach is alleen van toepassing op beheerde gegevensschijven. Als een vorige loskoppelpoging van de gegevensschijf niet is voltooid vanwege een onverwachte fout van de virtuele machine en de schijf nog steeds niet wordt vrijgegeven, gebruikt u force-loskoppelen als laatste redmiddeloptie om de schijf geforceerd los te koppelen van de virtuele machine. Alle schrijfbewerkingen zijn mogelijk niet leeggemaakt wanneer u dit loskoppelgedrag gebruikt.
Deze functie is nog in preview-versie. Als u een gegevensschijfupdate wilt afdwingen naarBeDetached in 'true' samen met de instelling detachOption: 'ForceDetach'.
|
|
DiskEncryptionSetParameters
|
Beschrijft de parameter van de resource-id van de door de klant beheerde schijfversleutelingsset die kan worden opgegeven voor schijf.
Opmerking: de resource-id van de schijfversleutelingsset kan alleen worden opgegeven voor beheerde schijven. Raadpleeg https://aka.ms/mdssewithcmkoverview voor meer informatie.
|
|
DiskEncryptionSettings
|
Beschrijft een versleutelingsinstellingen voor een schijf
|
|
DiskInstanceView
|
De exemplaarweergave van de schijf.
|
|
DomainNameLabelScopeTypes
|
Het bereik van het domeinnaamlabel. De samenvoeging van het gehashte domeinnaamlabel dat is gegenereerd volgens het beleid van het bereik van domeinnaamlabels en de VM-index zijn de domeinnaamlabels van de PublicIPAddress-resources die worden gemaakt
|
|
EncryptionIdentity
|
Hiermee geeft u de beheerde identiteit op die door ADE wordt gebruikt om toegangstoken op te halen voor sleutelkluisbewerkingen.
|
|
EventGridAndResourceGraph
|
Hiermee geeft u eventGridAndResourceGraph gerelateerde configuraties voor geplande gebeurtenissen op.
|
|
ExtendedLocation
|
Het complexe type van de uitgebreide locatie.
|
|
ExtendedLocationTypes
|
Het type van de uitgebreide locatie.
|
|
HardwareProfile
|
Hiermee geeft u de hardware-instellingen voor de virtuele machine.
|
|
HostEndpointSettings
|
Hiermee geeft u bepaalde hosteindpuntinstellingen op.
|
|
HyperVGenerationType
|
Hiermee geeft u het HyperVGeneration-type dat is gekoppeld aan een resource
|
|
ImageReference
|
Hiermee geeft u informatie over de te gebruiken afbeelding. U kunt informatie opgeven over platforminstallatiekopieën, marketplace-installatiekopieën of installatiekopieën van virtuele machines. Dit element is vereist wanneer u een platforminstallatiekopie, marketplace-installatiekopie of installatiekopie van virtuele machines wilt gebruiken, maar niet wordt gebruikt in andere bewerkingen voor het maken. OPMERKING: De uitgever en aanbieding van afbeeldingsreferentie kunnen alleen worden ingesteld wanneer u de schaalset maakt.
|
|
InnerError
|
Interne foutdetails.
|
|
InstanceViewStatus
|
Status van exemplaarweergave.
|
|
InterconnectBlockProfile
|
De parameters van een Interconnect Block Profile.
|
|
InterconnectGroupProfile
|
Specificeert het interconnect-groepprofiel voor een virtuele machine, gebruikt om de VM te koppelen aan een interconnect-groep en subgroepen.
|
|
InterconnectInstanceView
|
De details van de Interconnect Block-instantie voor een Virtual Machine of Scale Set VM-instantie.
|
|
IPVersions
|
Vanaf Api-Version 2017-03-30 wordt aangegeven of de specifieke ipconfiguratie IPv4 of IPv6 is. De standaardwaarde wordt gebruikt als IPv4. Mogelijke waarden zijn: 'IPv4' en 'IPv6'.
|
|
KeyVaultKeyReference
|
Beschrijft een verwijzing naar Key Vault-sleutel
|
|
KeyVaultSecretReference
|
Beschrijft een verwijzing naar Key Vault-geheim
|
|
LastPatchInstallationSummary
|
Beschrijft de eigenschappen van de laatst geïnstalleerde patchsamenvatting.
|
|
LinuxConfiguration
|
Hiermee geeft u de linux-besturingssysteeminstellingen op de virtuele machine. Zie Linux op Azure-Endorsed Distributiesvoor een lijst met ondersteunde Linux-distributies.
|
|
LinuxPatchAssessmentMode
|
Hiermee geeft u de modus van vm-gastpatchevaluatie voor de virtuele IaaS-machine.
Mogelijke waarden zijn:
ImageDefault-: u bepaalt de timing van patchevaluaties op een virtuele machine.
AutomaticByPlatform - Het platform activeert periodieke patchevaluaties. De eigenschap provisionVMAgent moet waar zijn.
|
|
LinuxPatchSettings
|
Hiermee geeft u instellingen met betrekking tot VM-gastpatching op Linux.
|
|
LinuxVMGuestPatchAutomaticByPlatformRebootSetting
|
Hiermee geeft u de instelling voor opnieuw opstarten voor alle installatiebewerkingen van de AutomaticByPlatform-patch.
|
|
LinuxVMGuestPatchAutomaticByPlatformSettings
|
Hiermee geeft u aanvullende instellingen op die moeten worden toegepast wanneer de patchmodus AutomaticByPlatform is geselecteerd in de Instellingen voor Linux-patches.
|
|
LinuxVMGuestPatchMode
|
Hiermee geeft u de modus van VM-gastpatching naar virtuele IaaS-machine of virtuele machines die zijn gekoppeld aan virtuele-machineschaalset met OrchestrationMode als Flexibel.
Mogelijke waarden zijn:
ImageDefault : de standaardpatchingconfiguratie van de virtuele machine wordt gebruikt.
AutomaticByPlatform : de virtuele machine wordt automatisch bijgewerkt door het platform. De eigenschap provisionVMAgent moet waar zijn
|
|
MaintenanceOperationResultCodeTypes
|
De resultaatcode van de laatste onderhoudsbewerking.
|
|
MaintenanceRedeployStatus
|
Onderhoudsbewerkingsstatus.
|
|
ManagedDiskParameters
|
De parameters van een beheerde schijf.
|
|
ManagedDiskProperties
|
Specificeert de eigenschappen van een beheerde schijf die kunnen worden ingesteld op het moment van impliciete creatie van de schijf.
|
|
Mode
|
Hiermee geeft u de modus op waarop ProxyAgent wordt uitgevoerd als de functie is ingeschakeld. ProxyAgent begint met controleren of bewaken, maar dwingt geen toegangsbeheer af over aanvragen voor hosteindpunten in de controlemodus, terwijl in de modus Afdwingen het toegangsbeheer wordt afgedwongen. De standaardwaarde is de modus Afdwingen.
|
|
Modes
|
Hiermee geeft u de uitvoeringsmodus. In de controlemodus fungeert het systeem alsof het het toegangsbeheerbeleid afdwingt, inclusief het verzenden van toegangsontkenningsvermeldingen in de logboeken, maar het weigert geen aanvragen voor hosteindpunten. In de modus Afdwingen dwingt het systeem het toegangsbeheer af en is het de aanbevolen bewerkingsmodus.
|
|
NetworkAccessPolicy
|
Beleid voor toegang tot de schijf via het netwerk.
|
|
NetworkApiVersion
|
hiermee geeft u de Microsoft.Network API-versie op die wordt gebruikt bij het maken van netwerkresources in de netwerkinterfaceconfiguraties
|
|
NetworkInterfaceAuxiliaryMode
|
Hiermee geeft u op of de hulpmodus is ingeschakeld voor de netwerkinterfaceresource.
|
|
NetworkInterfaceAuxiliarySku
|
Hiermee geeft u op of de hulp-sku is ingeschakeld voor de netwerkinterfaceresource.
|
|
NetworkInterfaceReference
|
Beschrijft een netwerkinterfacereferentie.
|
|
NetworkProfile
|
Hiermee geeft u de netwerkinterfaces of de netwerkconfiguratie van de virtuele machine.
|
|
OperatingSystemTypes
|
Met deze eigenschap kunt u het type besturingssysteem opgeven dat op de schijf is opgenomen als u een virtuele machine maakt op basis van een aangepaste installatiekopie. Mogelijke waarden zijn: Windows,Linux.
|
|
OSDisk
|
Hiermee geeft u informatie op over de besturingssysteemschijf die wordt gebruikt door de virtuele machine. Zie Over schijven en VHD's voor virtuele Azure-machinesvoor meer informatie over schijven.
|
|
OSImageNotificationProfile
|
|
|
OSProfile
|
Hiermee geeft u de besturingssysteeminstellingen voor de virtuele machine. Sommige instellingen kunnen niet worden gewijzigd zodra de VIRTUELE machine is ingericht.
|
|
PassNames
|
|
|
PatchOperationStatus
|
De algehele succes- of mislukkingsstatus van de operatie. Het blijft "InProgress" totdat de bewerking is voltooid. Op dat moment wordt het "Onbekend", "Mislukt", "Geslaagd" of "VoltooidMetWaarschuwingen".
|
|
PatchSettings
|
Hiermee geeft u instellingen met betrekking tot VM-gastpatching in Windows.
|
|
Placement
|
Beschrijft de door de gebruiker gedefinieerde beperkingen voor de plaatsing van resourcehardware.
|
|
Plan
|
Hiermee geeft u informatie op over de marketplace-installatiekopieën die worden gebruikt om de virtuele machine te maken. Dit element wordt alleen gebruikt voor Marketplace-installatiekopieën. Voordat u een Marketplace-installatiekopieën van een API kunt gebruiken, moet u de installatiekopieën inschakelen voor programmatisch gebruik. Zoek in Azure Portal de marketplace-installatiekopieën die u wilt gebruiken en klik vervolgens op Programmatisch wilt implementeren, Aan de slag ->. Voer de vereiste gegevens in en klik vervolgens op Opslaan.
|
|
ProcessorMode
|
Specificeert het processorfrequentiegedrag voor de virtuele machine. Bekijk elk lid voor het gedrag dat het controleert.
|
|
ProtocolTypes
|
Hiermee geeft u het protocol van WinRM-listener. Mogelijke waarden zijn: http,https.
|
|
ProxyAgentSettings
|
Hiermee geeft u ProxyAgent-instellingen voor de virtuele machine of virtuele-machineschaalset. Minimale API-versie: 2023-09-01.
|
|
PublicIPAddressSku
|
Beschrijft de openbare IP-SKU. Deze kan alleen worden ingesteld met OrchestrationMode als Flexible.
|
|
PublicIPAddressSkuName
|
Geef de naam van de openbare IP-SKU op
|
|
PublicIPAddressSkuTier
|
Openbare IP-SKU-laag opgeven
|
|
PublicIPAllocationMethod
|
Geef het type openbare IP-toewijzing op
|
|
ResiliencyProfile
|
Schakelt veerkrachtoplossingen in op de VM. Dit omvat back-up- of rampenhersteloplossingen.
|
|
ResourceIdentityType
|
Het type identiteit dat wordt gebruikt voor de virtuele machine. Het type SystemAssigned, UserAssigned bevat zowel een impliciet gemaakte identiteit als een set door de gebruiker toegewezen identiteiten. Met het type None worden alle identiteiten van de virtuele machine verwijderd.
|
|
ScheduledEventsAdditionalPublishingTargets
|
|
|
ScheduledEventsPolicy
|
Hiermee geeft u configuraties op die betrekking hebben op opnieuw implementeren, opnieuw opstarten en ScheduledEventsAdditionalPublishingTargets Scheduled Event.
|
|
ScheduledEventsProfile
|
|
|
SecurityEncryptionTypes
|
Hiermee geeft u het EncryptionType van de beheerde schijf. Deze is ingesteld op DiskWithVMGuestState voor versleuteling van de beheerde schijf, samen met VMGuestState-blob, VMGuestStateOnly voor versleuteling van alleen de VMGuestState-blob en NonPersistedTPM voor het niet behouden van de firmwarestatus in de VMGuestState-blob..
Opmerking: Deze kan alleen worden ingesteld voor vertrouwelijke VM's.
|
|
SecurityProfile
|
Hiermee geeft u de beveiligingsprofielinstellingen voor de virtuele machine of virtuele-machineschaalset op.
|
|
SecurityTypes
|
Specificeert de VM securityType; UefiSettings zijn alleen ingeschakeld wanneer ingesteld op TrustedLaunch of ConfidentialVM, en geven een standaardwaarde terug vanaf API-versie 2025-11-01.
|
|
SettingNames
|
Hiermee geeft u de naam op van de instelling waarop de inhoud van toepassing is. Mogelijke waarden zijn: FirstLogonCommands en AutoLogon.
|
|
SshConfiguration
|
SSH-configuratie voor op Linux gebaseerde VM's die worden uitgevoerd in Azure
|
|
SshPublicKey
|
Bevat informatie over de openbare SSH-certificaatsleutel en het pad op de Virtuele Linux-machine waarop de openbare sleutel wordt geplaatst.
|
|
StatusLevelTypes
|
De niveaucode.
|
|
StorageAccountTypes
|
Hiermee geeft u het type opslagaccount voor de beheerde schijf. Het opslagaccounttype beheerde besturingssysteemschijf kan alleen worden ingesteld wanneer u de schaalset maakt. OPMERKING: UltraSSD_LRS kan alleen worden gebruikt met gegevensschijven. Het kan niet worden gebruikt met besturingssysteemschijf. Standard_LRS maakt gebruik van Standard HDD. StandardSSD_LRS maakt gebruik van Standard SSD. Premium_LRS maakt gebruik van Premium SSD. UltraSSD_LRS maakt gebruik van Ultra disk. Premium_ZRS maakt gebruik van premium SSD-zone-redundante opslag. StandardSSD_ZRS maakt gebruik van zone-redundante opslag met Standard SSD. Raadpleeg voor meer informatie over schijven die worden ondersteund voor Virtuele Windows-machines https://docs.microsoft.com/azure/virtual-machines/windows/disks-types en raadpleeg voor Virtuele Linux-machines https://docs.microsoft.com/azure/virtual-machines/linux/disks-types
|
|
StorageAlignmentStatus
|
Specificeert de opslaguitlijningsstatus voor de schijf.
|
|
StorageFaultDomainAlignmentType
|
Specificeert het type uitlijning van het opslagfoutdomein voor de schijf.
|
|
StorageProfile
|
Hiermee geeft u de opslaginstellingen voor de schijven van de virtuele machine op.
|
|
SubResource
|
|
|
systemData
|
Metagegevens met betrekking tot het maken en de laatste wijziging van de resource.
|
|
TerminateNotificationProfile
|
|
|
UefiSettings
|
Hiermee geeft u de beveiligingsinstellingen op, zoals beveiligd opstarten en vTPM die worden gebruikt tijdens het maken van de virtuele machine. Minimale API-versie: 2020-12-01.
|
|
UserInitiatedReboot
|
Hiermee geeft u gerelateerde configuraties voor geplande gebeurtenissen opnieuw opstarten op.
|
|
UserInitiatedRedeploy
|
Hiermee geeft u gerelateerde configuraties voor geplande gebeurtenissen opnieuw implementeren.
|
|
VaultCertificate
|
Beschrijft één certificaatverwijzing in een Sleutelkluis en waar het certificaat zich op de virtuele machine moet bevinden.
|
|
VaultSecretGroup
|
Beschrijft een set certificaten die zich allemaal in dezelfde Key Vault bevinden.
|
|
VirtualHardDisk
|
Beschrijft de URI van een schijf.
|
|
VirtualMachine
|
Beschrijft een virtuele machine.
|
|
VirtualMachineAgentInstanceView
|
De exemplaarweergave van de VM-agent die wordt uitgevoerd op de virtuele machine.
|
|
VirtualMachineEvictionPolicyTypes
|
Hiermee geeft u het uitzettingsbeleid op voor de Azure Spot VM/VMSS
|
|
VirtualMachineExtension
|
Beschrijft een virtuele-machineextensie.
|
|
VirtualMachineExtensionHandlerInstanceView
|
De exemplaarweergave van een handler voor de extensie van een virtuele machine.
|
|
VirtualMachineExtensionInstanceView
|
De exemplaarweergave van een virtuele-machineextensie.
|
|
VirtualMachineHealthStatus
|
De status van de virtuele machine.
|
|
VirtualMachineIdentity
|
Identiteit voor de virtuele machine.
|
|
VirtualMachineInstanceView
|
De exemplaarweergave van een virtuele machine.
|
|
VirtualMachineIpTag
|
Bevat de IP-tag die is gekoppeld aan het openbare IP-adres.
|
|
VirtualMachineNetworkInterfaceConfiguration
|
Beschrijft een netwerkinterfaceconfiguratie voor virtuele machines.
|
|
VirtualMachineNetworkInterfaceDnsSettingsConfiguration
|
Beschrijft de DNS-instellingen van de netwerkconfiguratie van een virtuele machine.
|
|
VirtualMachineNetworkInterfaceIPConfiguration
|
Beschrijft de IP-configuratie van een netwerkprofiel voor een virtuele machine.
|
|
VirtualMachinePatchStatus
|
De status van patchbewerkingen voor virtuele machines.
|
|
VirtualMachinePriorityTypes
|
Hiermee geeft u de prioriteit op voor een zelfstandige virtuele machine of de virtuele machines in de schaalset.
|
|
VirtualMachinePublicIPAddressConfiguration
|
Beschrijft de publicIPAddress-configuratie van een virtuele machine
|
|
VirtualMachinePublicIPAddressDnsSettingsConfiguration
|
Beschrijft de DNS-instellingen van de netwerkconfiguratie van een virtuele machine.
|
|
VirtualMachineSizeTypes
|
Hiermee geeft u de grootte van de virtuele machine. Het enum-gegevenstype is momenteel afgeschaft en wordt op 23 december 2023 verwijderd. De aanbevolen manier om de lijst met beschikbare grootten op te halen, is met behulp van deze API's: Alle beschikbare grootten van virtuele machines in een beschikbaarheidsset weergeven, Alle beschikbare grootten van virtuele machines in een regio weergeven, Alle beschikbare grootten van virtuele machines weergeven voor het wijzigen van de grootte van. Zie Grootten voor virtuele machinesvoor meer informatie over de grootte van virtuele machines. De beschikbare VM-grootten zijn afhankelijk van de regio en beschikbaarheidsset.
|
|
VMDiskSecurityProfile
|
Hiermee geeft u de beveiligingsprofielinstellingen voor de beheerde schijf.
Opmerking: Deze kan alleen worden ingesteld voor vertrouwelijke VM's.
|
|
VMGalleryApplication
|
Hiermee geeft u de vereiste informatie om te verwijzen naar een toepassingsversie van een rekengalerie
|
|
VMSizeProperties
|
Hiermee geeft u de instellingen voor de eigenschap VM-grootte op de virtuele machine.
|
|
WindowsConfiguration
|
Hiermee geeft u windows-besturingssysteeminstellingen op de virtuele machine.
|
|
WindowsPatchAssessmentMode
|
Hiermee geeft u de modus van vm-gastpatchevaluatie voor de virtuele IaaS-machine.
Mogelijke waarden zijn:
ImageDefault-: u bepaalt de timing van patchevaluaties op een virtuele machine.
AutomaticByPlatform - Het platform activeert periodieke patchevaluaties. De eigenschap provisionVMAgent moet waar zijn.
|
|
WindowsVMGuestPatchAutomaticByPlatformRebootSetting
|
Hiermee geeft u de instelling voor opnieuw opstarten voor alle installatiebewerkingen van de AutomaticByPlatform-patch.
|
|
WindowsVMGuestPatchAutomaticByPlatformSettings
|
Hiermee geeft u aanvullende instellingen op die moeten worden toegepast wanneer de patchmodus AutomaticByPlatform is geselecteerd in de Windows-patchinstellingen.
|
|
WindowsVMGuestPatchMode
|
Hiermee geeft u de modus van VM-gastpatching naar virtuele IaaS-machine of virtuele machines die zijn gekoppeld aan virtuele-machineschaalset met OrchestrationMode als Flexibel.
Mogelijke waarden zijn:
Handmatig: u beheert de toepassing van patches op een virtuele machine. U doet dit door patches handmatig toe te passen in de VIRTUELE machine. In deze modus worden automatische updates uitgeschakeld; de eigenschap WindowsConfiguration.enableAutomaticUpdates moet onwaar zijn
AutomaticByOS : de virtuele machine wordt automatisch bijgewerkt door het besturingssysteem. De eigenschap WindowsConfiguration.enableAutomaticUpdates moet waar zijn.
AutomaticByPlatform : de virtuele machine wordt automatisch bijgewerkt door het platform. De eigenschappen provisionVMAgent en WindowsConfiguration.enableAutomaticUpdates moeten waar zijn
|
|
WinRMConfiguration
|
Hierin wordt de configuratie van Windows Remote Management van de VM beschreven
|
|
WinRMListener
|
Beschrijft protocol en vingerafdruk van Windows Remote Management-listener
|
|
ZoneMovement
|
Beschrijft de configuratie van zonebewegingen. Dit maakt het mogelijk om VM tijdens een storing tussen beschikbaarheidszones te verplaatsen.
|
|
ZonePlacementPolicyType
|
Hiermee geeft u het beleid op voor de plaatsing van de resource in de beschikbaarheidszone. Mogelijke waarden zijn: Alle (gebruikt voor virtuele machines), Auto (gebruikt voor virtuele-machineschaalsets) - Een beschikbaarheidszone wordt automatisch door het systeem gekozen als onderdeel van het maken van resources.
|
AdditionalCapabilities
Object
Hiermee schakelt u een mogelijkheid op de virtuele machine of virtuele-machineschaalset in of uit.
| Name |
Type |
Description |
|
enableFips1403Encryption
|
boolean
|
De vlag maakt het gebruik van FIPS 140-3-compatibele cryptografie mogelijk op de protectedSettings van een extensie. Meer informatie vindt u op: https://aka.ms/linuxagentfipssupport.
|
|
hibernationEnabled
|
boolean
|
De vlag waarmee de sluimerstand op de VIRTUELE machine wordt ingeschakeld of uitgeschakeld.
|
|
ultraSSDEnabled
|
boolean
|
De vlag waarmee een mogelijkheid wordt ingeschakeld of uitgeschakeld voor een of meer beheerde gegevensschijven met UltraSSD_LRS opslagaccounttype op de VIRTUELE machine of VMSS. Beheerde schijven met het type opslagaccount UltraSSD_LRS kunnen alleen worden toegevoegd aan een virtuele machine of virtuele-machineschaalset als deze eigenschap is ingeschakeld.
|
AdditionalDiskProperties
Object
Specificeert aanvullende eigenschappen voor een beheerde schijf die kunnen worden ingesteld op het moment van impliciete creatie van de schijf.
| Name |
Type |
Description |
|
managedDiskProperties
|
ManagedDiskProperties
|
Specificeert de beheerde schijfeigenschappen die kunnen worden ingesteld op het moment van impliciete creatie van de schijf.
|
AdditionalUnattendContent
Object
Hiermee geeft u aanvullende XML-opgemaakte informatie op die kan worden opgenomen in het Unattend.xml-bestand, dat wordt gebruikt door Windows Setup. De inhoud wordt gedefinieerd door de naam van de instelling, de onderdeelnaam en de pass waarin de inhoud wordt toegepast.
| Name |
Type |
Description |
|
componentName
|
ComponentNames
|
De naam van het onderdeel. Momenteel is de enige toegestane waarde Microsoft-Windows-Shell-Setup.
|
|
content
|
string
|
Hiermee geeft u de xml-opgemaakte inhoud op die wordt toegevoegd aan het unattend.xml-bestand voor het opgegeven pad en het opgegeven onderdeel. De XML moet kleiner zijn dan 4 kB en moet het hoofdelement bevatten voor de instelling of functie die wordt ingevoegd.
|
|
passName
|
PassNames
|
De wachtwoordnaam. Momenteel is de enige toegestane waarde OobeSystem.
|
|
settingName
|
SettingNames
|
Hiermee geeft u de naam op van de instelling waarop de inhoud van toepassing is. Mogelijke waarden zijn: FirstLogonCommands en AutoLogon.
|
AllInstancesDown
Object
Geeft aan of geplande gebeurtenissen automatisch moeten worden goedgekeurd wanneer alle exemplaren niet beschikbaar zijn.
| Name |
Type |
Description |
|
automaticallyApprove
|
boolean
|
Geeft aan of geplande gebeurtenissen automatisch moeten worden goedgekeurd wanneer alle exemplaren niet beschikbaar zijn.
De standaardwaarde is waar
|
ApiEntityReference
Object
De API-entiteitsreferentie.
| Name |
Type |
Description |
|
id
|
string
|
De ARM-resource-id in de vorm van /subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroupName}/...
|
ApiError
Object
Api-fout.
| Name |
Type |
Description |
|
code
|
string
|
De foutcode.
|
|
details
|
ApiErrorBase[]
|
Details van de API-fout
|
|
innererror
|
InnerError
|
De interne API-fout
|
|
message
|
string
|
Het foutbericht.
|
|
target
|
string
|
Het doel van de specifieke fout.
|
ApiErrorBase
Object
Api-foutbasis.
| Name |
Type |
Description |
|
code
|
string
|
De foutcode.
|
|
message
|
string
|
Het foutbericht.
|
|
target
|
string
|
Het doel van de specifieke fout.
|
ApplicationProfile
Object
Bevat de lijst met galerietoepassingen die beschikbaar moeten worden gesteld voor de VM/VMSS
| Name |
Type |
Description |
|
galleryApplications
|
VMGalleryApplication[]
|
Hiermee geeft u de galerietoepassingen op die beschikbaar moeten worden gesteld voor de VM/VMSS
|
AvailabilityPolicyDiskDelay
Opsomming
Bepaalt hoe schijven met trage I/O moeten worden verwerkt.
| Waarde |
Description |
|
None
|
Standaard staat gedrag aan zonder beschikbaarheidsbeleid, namelijk VM-herstart bij trage schijf-I/O.
|
|
AutomaticReattach
|
Bij een schijf-I/O-storing of trage respons, probeer de schijf los te koppelen en dan weer aan te sluiten.
|
AvailablePatchSummary
Object
Beschrijft de eigenschappen van een exemplaarweergave van een virtuele machine voor de beschikbare patchsamenvatting.
| Name |
Type |
Description |
|
assessmentActivityId
|
string
|
De activiteit-id van de bewerking die dit resultaat heeft opgeleverd. Het wordt gebruikt om te correleren tussen CRP- en extensielogboeken.
|
|
criticalAndSecurityPatchCount
|
integer
(int32)
|
Het aantal kritieke of beveiligingspatches dat is gedetecteerd als beschikbaar en nog niet is geïnstalleerd.
|
|
error
|
ApiError
|
De fouten die zijn opgetreden tijdens de uitvoering van de bewerking. De detailarray bevat de lijst ervan.
|
|
lastModifiedTime
|
string
(date-time)
|
Het UTC-tijdstempel wanneer de bewerking begon.
|
|
otherPatchCount
|
integer
(int32)
|
Het aantal beschikbare patches, met uitzondering van kritieke en beveiliging.
|
|
rebootPending
|
boolean
|
De algehele herstartstatus van de VM. Dit zal het geval zijn wanneer gedeeltelijk geïnstalleerde patches opnieuw moeten worden opgestart om de installatie te voltooien, maar de herstart nog niet heeft plaatsgevonden.
|
|
startTime
|
string
(date-time)
|
Het UTC-tijdstempel wanneer de bewerking begon.
|
|
status
|
PatchOperationStatus
|
De algehele succes- of mislukkingsstatus van de operatie. Het blijft "InProgress" totdat de bewerking is voltooid. Op dat moment wordt het "Onbekend", "Mislukt", "Geslaagd" of "VoltooidMetWaarschuwingen".
|
BillingProfile
Object
Hiermee geeft u de factureringsgerelateerde details van een Azure Spot-VM of VMSS op. Minimale API-versie: 2019-03-01.
| Name |
Type |
Description |
|
maxPrice
|
number
(double)
|
Hiermee geeft u de maximumprijs op die u wilt betalen voor een Azure Spot VM/VMSS. Deze prijs is in Amerikaanse dollars.
Deze prijs wordt vergeleken met de huidige Azure Spot-prijs voor de VM-grootte. De prijzen worden ook vergeleken op het moment van het maken/bijwerken van Azure Spot VM/VMSS en de bewerking slaagt alleen als de maxPrice groter is dan de huidige Azure Spot-prijs.
De maxPrice wordt ook gebruikt voor het verwijderen van een Azure Spot-VM/VMSS als de huidige Azure Spot-prijs hoger is dan de maxPrice na het maken van VM/VMSS.
Mogelijke waarden zijn:
- Elke decimale waarde groter dan nul. Voorbeeld: 0.01538
-1 – geeft aan dat de standaardprijs moet worden up-to op aanvraag.
U kunt de maxPrice instellen op -1 om aan te geven dat de Azure Spot-VM/VMSS om prijsredenen niet mag worden verwijderd. De standaardprijs is ook -1 als deze niet door u wordt verstrekt.
Minimale API-versie: 2019-03-01.
|
BootDiagnostics
Object
Diagnostische gegevens over opstarten is een functie voor foutopsporing waarmee u console-uitvoer en schermopname kunt bekijken om de VM-status te diagnosticeren. U kunt eenvoudig de uitvoer van uw consolelogboek bekijken. Met Azure kunt u ook een schermopname van de virtuele machine bekijken vanuit de hypervisor.
| Name |
Type |
Description |
|
enabled
|
boolean
|
Of diagnostische gegevens over opstarten moeten worden ingeschakeld op de virtuele machine.
|
|
storageUri
|
string
|
Uri van het opslagaccount dat moet worden gebruikt voor het plaatsen van de console-uitvoer en schermopname. Als storageUri niet is opgegeven tijdens het inschakelen van diagnostische gegevens over opstarten, wordt beheerde opslag gebruikt.
|
BootDiagnosticsInstanceView
Object
De exemplaarweergave van diagnostische gegevens over opstarten van virtuele machines.
| Name |
Type |
Description |
|
consoleScreenshotBlobUri
|
string
|
De schermafbeelding van de blob-URI van de console.
Opmerking: Dit niet worden ingesteld als diagnostische gegevens over opstarten momenteel zijn ingeschakeld met beheerde opslag.
|
|
serialConsoleLogBlobUri
|
string
|
De blob-URI van het seriële consolelogboek.
Opmerking: Dit niet worden ingesteld als diagnostische gegevens over opstarten momenteel zijn ingeschakeld met beheerde opslag.
|
|
status
|
InstanceViewStatus
|
De statusinformatie over diagnostische gegevens over opstarten voor de virtuele machine.
Opmerking: Deze wordt alleen ingesteld als er fouten zijn opgetreden bij het inschakelen van diagnostische gegevens over opstarten.
|
CachingTypes
Opsomming
Hiermee geeft u de cachevereisten op. Mogelijke waarden zijn: Geen,Alleen-lezen,Lezen'. De standaardwaarden zijn: Geen voor standaardopslag. ReadOnly voor Premium opslag
| Waarde |
Description |
|
None
|
|
|
ReadOnly
|
|
|
ReadWrite
|
|
CapacityReservationProfile
Object
De parameters van een capaciteitsreserveringsprofiel.
| Name |
Type |
Description |
|
capacityReservationGroup
|
SubResource
|
Hiermee geeft u de resource-id van de capaciteitsreserveringsgroep op die moet worden gebruikt voor het toewijzen van de vm-exemplaren van de virtuele machine of scaleset, mits er voldoende capaciteit is gereserveerd. Raadpleeg https://aka.ms/CapacityReservation voor meer informatie.
|
|
disableCapacityReservationAssignment
|
boolean
|
Specificeert of de virtuele machine expliciet is afgestemd op het worden gekoppeld aan een capaciteitsreservering. Wanneer deze op true wordt gezet, mag de virtuele machine niet impliciet of expliciet associëren met een type capaciteitsreservering en zal deze capaciteit verbruiken van de publiek beschikbare capaciteit. Minimale api-versie: 2026-04-01.
|
CapacityReservationType
Opsomming
Specificeert van welk type capaciteitsreservering de virtuele machine capaciteit zal verbruiken als deze in aanmerking komt, of dat deze expliciet is afgestemd op het gekoppeld zijn en verbruiken van capaciteit uit elke gereserveerde capaciteit die beschikbaar is in het abonnement. Minimale api-versie: 2026-04-01.
| Waarde |
Description |
|
NotEligible
|
De virtuele machine komt niet in aanmerking om impliciet gekoppeld te worden aan een open capaciteitsreservering en is ook niet expliciet gekoppeld aan een capaciteitsreserveringsgroep, dus deze verbruikt capaciteit uit de publiek beschikbare capaciteit.
|
|
Targeted
|
De virtuele machine verbruikt capaciteit van een specifieke matching capaciteitsreservering wanneer deze is gekoppeld aan een capaciteitsreserveringsgroepresource van het type dat wordt getarget, maar kan terugvallen op capaciteit uit de publiek beschikbare capaciteit als er geen capaciteit beschikbaar is in de beoogde reservering.
|
|
Open
|
De virtuele machine, indien in aanmerking kom, zal impliciet alle beschikbare capaciteit koppelen en gebruiken uit een bijpassende open capaciteitsreservering die in het abonnement is gemaakt of gedeeld.
Opmerking: De VM mag niet expliciet gekoppeld zijn aan de open capaciteitsreserveringsgroep resource die de bijbehorende reservering bevat.
|
|
Disabled
|
De virtuele machine heeft capaciteitsreserveringstoewijzing uitgeschakeld en mag niet impliciet of expliciet gekoppeld worden aan enig type capaciteitsreservering.
|
|
Block
|
De virtuele machine verbruikt capaciteit van een specifieke overeenkomstige capaciteitsreservering wanneer deze is gekoppeld aan een capaciteitsreserveringsgroepresource van het type blok, en zal capaciteitsuitval ondervinden als er geen beschikbare capaciteit is in de blokreservering.
|
CloudError
Object
Een foutreactie van de Compute-service.
| Name |
Type |
Description |
|
error
|
ApiError
|
Api-fout.
|
Common.UserAssignedIdentitiesValue
Object
| Name |
Type |
Description |
|
clientId
|
string
|
De client-id van de door de gebruiker toegewezen identiteit.
|
|
principalId
|
string
|
De principal-id van de door de gebruiker toegewezen identiteit.
|
ComponentNames
Opsomming
| Waarde |
Description |
|
Microsoft-Windows-Shell-Setup
|
|
createdByType
Opsomming
Het identiteitstype dat de resource heeft gemaakt.
| Waarde |
Description |
|
User
|
|
|
Application
|
|
|
ManagedIdentity
|
|
|
Key
|
|
DataDisk
Object
Beschrijft een gegevensschijf.
| Name |
Type |
Description |
|
caching
|
CachingTypes
|
Hiermee geeft u de cachevereisten op. Mogelijke waarden zijn: None,ReadOnlyReadWrite. Het standaardgedrag is: Geen voor Standard-opslag. ReadOnly voor Premium-opslag.
|
|
createOption
|
DiskCreateOptionTypes
|
Hiermee geeft u op hoe de schijf van de virtuele machine moet worden gemaakt. Mogelijke waarden zijn Koppelen: Deze waarde wordt gebruikt wanneer u een gespecialiseerde schijf gebruikt om de virtuele machine te maken.
FromImage: Deze waarde wordt gebruikt wanneer u een installatiekopie gebruikt om de gegevensschijf van de virtuele machine te maken. Als u een platforminstallatiekopie gebruikt, moet u ook het element imageReference gebruiken dat hierboven wordt beschreven. Als u een marketplace-installatiekopieën gebruikt, moet u ook het eerder beschreven planelement gebruiken.
Leeg: Deze waarde wordt gebruikt bij het maken van een lege gegevensschijf.
Kopiëren: Deze waarde wordt gebruikt om een gegevensschijf te maken op basis van een momentopname of een andere schijf.
Herstellen: Deze waarde wordt gebruikt om een gegevensschijf te maken vanaf een schijfherstelpunt.
|
|
deleteOption
|
DiskDeleteOptionTypes
|
Hiermee geeft u op of de gegevensschijf moet worden verwijderd of losgekoppeld bij het verwijderen van de virtuele machine. Mogelijke waarden zijn: Verwijderen. Als deze waarde wordt gebruikt, wordt de gegevensschijf verwijderd wanneer de VIRTUELE machine wordt verwijderd. Loskoppelen. Als deze waarde wordt gebruikt, blijft de gegevensschijf behouden nadat de VIRTUELE machine is verwijderd. De standaardwaarde is ingesteld op Loskoppelen.
|
|
detachOption
|
DiskDetachOptionTypes
|
Hiermee geeft u het loskoppelgedrag op dat moet worden gebruikt tijdens het loskoppelen van een schijf of die al bezig is met loskoppelen van de virtuele machine. Ondersteunde waarden: ForceDetach. detachOption: ForceDetach- is alleen van toepassing op beheerde gegevensschijven. Als een vorige loskoppelpoging van de gegevensschijf niet is voltooid vanwege een onverwachte fout van de virtuele machine en de schijf nog steeds niet wordt vrijgegeven, gebruikt u force-loskoppelen als laatste redmiddeloptie om de schijf geforceerd los te koppelen van de virtuele machine. Alle schrijfbewerkingen zijn mogelijk niet leeggemaakt wanneer u dit loskoppelgedrag gebruikt.
Deze functie is nog in preview-versie. Als u een gegevensschijfupdate wilt afdwingen naarBeDetached in 'true' samen met de instelling detachOption: 'ForceDetach'.
|
|
diskIOPSReadWrite
|
integer
(int64)
|
Hiermee geeft u de Read-Write IOPS voor de beheerde schijf wanneer StorageAccountType is UltraSSD_LRS.
|
|
diskMBpsReadWrite
|
integer
(int64)
|
Hiermee geeft u de bandbreedte in MB per seconde voor de beheerde schijf op wanneer StorageAccountType is UltraSSD_LRS.
|
|
diskSizeGB
|
integer
(int32)
|
Hiermee geeft u de grootte van een lege gegevensschijf in gigabytes. Dit element kan worden gebruikt om de grootte van de schijf in een installatiekopieën van een virtuele machine te overschrijven. De eigenschap diskSizeGB is het aantal bytes x 1024^3 voor de schijf en de waarde mag niet groter zijn dan 1023.
|
|
image
|
VirtualHardDisk
|
De virtuele harde schijf van de brongebruiker. De virtuele harde schijf wordt gekopieerd voordat deze aan de virtuele machine wordt gekoppeld. Als SourceImage is opgegeven, mag de virtuele doelschijf niet bestaan.
|
|
lun
|
integer
(int32)
|
Hiermee geeft u het nummer van de logische eenheid van de gegevensschijf. Deze waarde wordt gebruikt om gegevensschijven binnen de VIRTUELE machine te identificeren en moet daarom uniek zijn voor elke gegevensschijf die is gekoppeld aan een VIRTUELE machine.
|
|
managedDisk
|
ManagedDiskParameters
|
De parameters van de beheerde schijf.
|
|
name
|
string
|
De naam van de schijf.
|
|
sourceResource
|
ApiEntityReference
|
De bronresource-id. Het kan een momentopname of een schijfherstelpunt zijn van waaruit een schijf moet worden gemaakt.
|
|
storageFaultDomainAlignment
|
StorageFaultDomainAlignmentType
|
Specificeert het type uitlijning van het opslagfoutdomein voor de schijf.
|
|
toBeDetached
|
boolean
|
Hiermee geeft u op of de gegevensschijf wordt losgekoppeld van de VirtualMachine/VirtualMachineScaleset
|
|
vhd
|
VirtualHardDisk
|
De virtuele harde schijf.
|
|
writeAcceleratorEnabled
|
boolean
|
Hiermee geeft u op of writeAccelerator moet worden ingeschakeld of uitgeschakeld op de schijf.
|
DeleteOptions
Opsomming
Opgeven wat er gebeurt met de netwerkinterface wanneer de VIRTUELE machine wordt verwijderd
| Waarde |
Description |
|
Delete
|
|
|
Detach
|
|
DiagnosticsProfile
Object
Hiermee geeft u de status van diagnostische instellingen voor opstarten. Minimale API-versie: 2015-06-15.
| Name |
Type |
Description |
|
bootDiagnostics
|
BootDiagnostics
|
Diagnostische gegevens over opstarten is een functie voor foutopsporing waarmee u console-uitvoer en schermopname kunt bekijken om de VM-status te diagnosticeren.
OPMERKING: als storageUri wordt opgegeven, moet u ervoor zorgen dat het opslagaccount zich in dezelfde regio en hetzelfde abonnement bevindt als de virtuele machine. U kunt eenvoudig de uitvoer van uw consolelogboek bekijken. Met Azure kunt u ook een schermopname van de virtuele machine bekijken vanuit de hypervisor.
|
DiffDiskOptions
Opsomming
Hiermee geeft u de tijdelijke schijfoptie voor de besturingssysteemschijf.
DiffDiskPlacement
Opsomming
Hiermee geeft u de tijdelijke schijfplaatsing voor de besturingssysteemschijf. Deze eigenschap kan worden gebruikt door de gebruiker in de aanvraag om de locatie te kiezen, bijvoorbeeld de cacheschijf, de resourceschijf of de nvme-schijfruimte voor tijdelijke inrichting van besturingssysteemschijven. Voor meer informatie over tijdelijke vereisten voor besturingssysteemschijfgrootte, raadpleegt u kortstondige besturingssysteemschijfgroottevereisten voor Windows-VM op https://docs.microsoft.com/azure/virtual-machines/windows/ephemeral-os-disks#size-requirements en Linux-VM op https://docs.microsoft.com/azure/virtual-machines/linux/ephemeral-os-disks#size-requirements. Minimale API-versie voor NvmeDisk: 2024-03-01.
| Waarde |
Description |
|
CacheDisk
|
|
|
ResourceDisk
|
|
|
NvmeDisk
|
|
DiffDiskSettings
Object
Beschrijft de parameters van tijdelijke schijfinstellingen die kunnen worden opgegeven voor de besturingssysteemschijf.
Opmerking: De tijdelijke schijfinstellingen kunnen alleen worden opgegeven voor beheerde schijven.
| Name |
Type |
Description |
|
enableFullCaching
|
boolean
|
Geeft aan of volledige caching voor deze VM moet worden ingeschakeld, waardoor de OS-schijf lokaal op de host wordt gecachet en deze VM bestand wordt tegen opslaguitval
|
|
option
|
DiffDiskOptions
|
Hiermee geeft u de tijdelijke schijfinstellingen voor de besturingssysteemschijf.
|
|
placement
|
DiffDiskPlacement
|
Hiermee geeft u de tijdelijke schijfplaatsing voor de besturingssysteemschijf. Mogelijke waarden zijn: CacheDisk,ResourceDisk,NvmeDisk. Het standaardgedrag is: CacheDisk als deze is geconfigureerd voor de VM-grootte, anders wordt ResourceDisk of NvmeDisk- gebruikt. Raadpleeg de documentatie over de VM-grootte voor Windows-VM's op https://docs.microsoft.com/azure/virtual-machines/windows/sizes en Linux-VM op https://docs.microsoft.com/azure/virtual-machines/linux/sizes om te controleren welke VM-grootten een cacheschijf beschikbaar maken. Minimale API-versie voor NvmeDisk: 2024-03-01.
|
DiskApiVersion
Opsomming
Specificeert de Disk API-versie die wordt gebruikt bij het toepassen van additionalDiskProperties op beheerde schijven. De waarde moet in het formaat JJJJ-MM-DD zijn.
| Waarde |
Description |
|
2025-01-02
|
De Disk RP API-versie van 2025-01-02.
|
|
2026-03-02
|
De Disk RP API-versie van 2026-03-02.
|
DiskAvailabilityPolicy
Object
In het geval van een beschikbaarheids- of verbindingsprobleem met de schijf, specificeer dan het gedrag van je VM.
DiskControllerTypes
Opsomming
Hiermee geeft u het type schijfcontroller geconfigureerd voor de VIRTUELE machine en VirtualMachineScaleSet. Deze eigenschap wordt alleen ondersteund voor virtuele machines waarvan de besturingssysteemschijf en de VM-sku ondersteuning biedt voor generatie 2 (https://docs.microsoft.com/en-us/azure/virtual-machines/generation-2), controleert u de HyperVGenerations-functie die wordt geretourneerd als onderdeel van de SKU-mogelijkheden van de VM in het antwoord van de API voor Microsoft.Compute SKU's voor de regio bevat V2 (https://docs.microsoft.com/rest/api/compute/resourceskus/list). Raadpleeg voor meer informatie over ondersteunde https://aka.ms/azure-diskcontrollertypesschijfcontrollertypen.
| Waarde |
Description |
|
SCSI
|
|
|
NVMe
|
|
DiskCreateOptionTypes
Opsomming
Hiermee geeft u op hoe de schijf van de virtuele machine moet worden gemaakt. Mogelijke waarden zijn Koppelen: Deze waarde wordt gebruikt wanneer u een gespecialiseerde schijf gebruikt om de virtuele machine te maken.
FromImage: Deze waarde wordt gebruikt wanneer u een installatiekopie gebruikt om de virtuele machine te maken. Als u een platforminstallatiekopie gebruikt, moet u ook het element imageReference gebruiken dat hierboven wordt beschreven. Als u een marketplace-installatiekopieën gebruikt, moet u ook het eerder beschreven planelement gebruiken.
Leeg: Deze waarde wordt gebruikt bij het maken van een lege gegevensschijf.
Kopiëren: Deze waarde wordt gebruikt om een gegevensschijf te maken op basis van een momentopname of een andere schijf.
Herstellen: Deze waarde wordt gebruikt om een gegevensschijf te maken vanaf een schijfherstelpunt.
| Waarde |
Description |
|
FromImage
|
|
|
Empty
|
|
|
Attach
|
|
|
Copy
|
|
|
Restore
|
|
DiskDeleteOptionTypes
Opsomming
Hiermee geeft u het gedrag van de beheerde schijf op wanneer de virtuele machine wordt verwijderd, bijvoorbeeld of de beheerde schijf wordt verwijderd of losgekoppeld. Ondersteunde waarden zijn: Verwijderen. Als deze waarde wordt gebruikt, wordt de beheerde schijf verwijderd wanneer de VIRTUELE machine wordt verwijderd. Loskoppelen. Als deze waarde wordt gebruikt, blijft de beheerde schijf behouden nadat de VIRTUELE machine is verwijderd. Minimale API-versie: 2021-03-01.
| Waarde |
Description |
|
Delete
|
|
|
Detach
|
|
DiskDetachOptionTypes
Opsomming
Hiermee geeft u het loskoppelgedrag op dat moet worden gebruikt tijdens het loskoppelen van een schijf of die al bezig is met loskoppelen van de virtuele machine. Ondersteunde waarden zijn: ForceDetach. detachOption: ForceDetach is alleen van toepassing op beheerde gegevensschijven. Als een vorige loskoppelpoging van de gegevensschijf niet is voltooid vanwege een onverwachte fout van de virtuele machine en de schijf nog steeds niet wordt vrijgegeven, gebruikt u force-loskoppelen als laatste redmiddeloptie om de schijf geforceerd los te koppelen van de virtuele machine. Alle schrijfbewerkingen zijn mogelijk niet leeggemaakt wanneer u dit loskoppelgedrag gebruikt.
Deze functie is nog in preview-versie. Als u een gegevensschijfupdate wilt afdwingen naarBeDetached in 'true' samen met de instelling detachOption: 'ForceDetach'.
| Waarde |
Description |
|
ForceDetach
|
|
DiskEncryptionSetParameters
Object
Beschrijft de parameter van de resource-id van de door de klant beheerde schijfversleutelingsset die kan worden opgegeven voor schijf.
Opmerking: de resource-id van de schijfversleutelingsset kan alleen worden opgegeven voor beheerde schijven. Raadpleeg https://aka.ms/mdssewithcmkoverview voor meer informatie.
| Name |
Type |
Description |
|
id
|
string
|
Resource-id
|
DiskEncryptionSettings
Object
Beschrijft een versleutelingsinstellingen voor een schijf
| Name |
Type |
Description |
|
diskEncryptionKey
|
KeyVaultSecretReference
|
Hiermee geeft u de locatie van de schijfversleutelingssleutel, een Sleutelkluisgeheim.
|
|
enabled
|
boolean
|
Hiermee geeft u op of schijfversleuteling moet worden ingeschakeld op de virtuele machine.
|
|
keyEncryptionKey
|
KeyVaultKeyReference
|
Hiermee geeft u de locatie van de sleutelversleutelingssleutel in Key Vault.
|
DiskInstanceView
Object
De exemplaarweergave van de schijf.
| Name |
Type |
Description |
|
encryptionSettings
|
DiskEncryptionSettings[]
|
Hiermee geeft u de versleutelingsinstellingen voor de besturingssysteemschijf.
Minimale API-versie: 2015-06-15
|
|
name
|
string
|
De naam van de schijf.
|
|
statuses
|
InstanceViewStatus[]
|
De informatie over de resourcestatus.
|
|
storageAlignmentStatus
|
StorageAlignmentStatus
|
Specificeert de opslaguitlijningsstatus voor de schijf.
|
DomainNameLabelScopeTypes
Opsomming
Het bereik van het domeinnaamlabel. De samenvoeging van het gehashte domeinnaamlabel dat is gegenereerd volgens het beleid van het bereik van domeinnaamlabels en de VM-index zijn de domeinnaamlabels van de PublicIPAddress-resources die worden gemaakt
| Waarde |
Description |
|
TenantReuse
|
|
|
SubscriptionReuse
|
|
|
ResourceGroupReuse
|
|
|
NoReuse
|
|
EncryptionIdentity
Object
Hiermee geeft u de beheerde identiteit op die door ADE wordt gebruikt om toegangstoken op te halen voor sleutelkluisbewerkingen.
| Name |
Type |
Description |
|
userAssignedIdentityResourceId
|
string
|
Hiermee geeft u de ARM-resource-id op van een van de gebruikersidentiteiten die zijn gekoppeld aan de virtuele machine.
|
EventGridAndResourceGraph
Object
Hiermee geeft u eventGridAndResourceGraph gerelateerde configuraties voor geplande gebeurtenissen op.
| Name |
Type |
Description |
|
enable
|
boolean
|
Hiermee geeft u op of gebeurtenisraster en resourcegrafiek zijn ingeschakeld voor configuraties met betrekking tot geplande gebeurtenissen.
|
|
scheduledEventsApiVersion
|
string
|
Hiermee geeft u de api-versie op om te bepalen welke versie van het configuratieschema voor geplande gebeurtenissen wordt geleverd.
|
ExtendedLocation
Object
Het complexe type van de uitgebreide locatie.
| Name |
Type |
Description |
|
name
|
string
|
De naam van de uitgebreide locatie.
|
|
type
|
ExtendedLocationTypes
|
Het type van de uitgebreide locatie.
|
ExtendedLocationTypes
Opsomming
Het type van de uitgebreide locatie.
| Waarde |
Description |
|
EdgeZone
|
|
HardwareProfile
Object
Hiermee geeft u de hardware-instellingen voor de virtuele machine.
HostEndpointSettings
Object
Hiermee geeft u bepaalde hosteindpuntinstellingen op.
| Name |
Type |
Description |
|
inVMAccessControlProfileReferenceId
|
string
|
Hiermee geeft u de resource-id InVMAccessControlProfileVersion op in de indeling /subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/Microsoft.Compute/galleries/{galleryName}/inVMAccessControlProfiles/{profile}/versions/{version}
|
|
mode
|
Modes
|
Hiermee geeft u de uitvoeringsmodus. In de controlemodus fungeert het systeem alsof het het toegangsbeheerbeleid afdwingt, inclusief het verzenden van toegangsontkenningsvermeldingen in de logboeken, maar het weigert geen aanvragen voor hosteindpunten. In de modus Afdwingen dwingt het systeem het toegangsbeheer af en is het de aanbevolen bewerkingsmodus.
|
|
useLocalFileRules
|
boolean
|
Wanneer deze op true staat, instrueert de GuestProxyAgent binnen de VM om extra toegangscontroleregels te laden die in een lokaal bestand op de VM zijn gedefinieerd.
|
HyperVGenerationType
Opsomming
Hiermee geeft u het HyperVGeneration-type dat is gekoppeld aan een resource
ImageReference
Object
Hiermee geeft u informatie over de te gebruiken afbeelding. U kunt informatie opgeven over platforminstallatiekopieën, marketplace-installatiekopieën of installatiekopieën van virtuele machines. Dit element is vereist wanneer u een platforminstallatiekopie, marketplace-installatiekopie of installatiekopie van virtuele machines wilt gebruiken, maar niet wordt gebruikt in andere bewerkingen voor het maken. OPMERKING: De uitgever en aanbieding van afbeeldingsreferentie kunnen alleen worden ingesteld wanneer u de schaalset maakt.
| Name |
Type |
Description |
|
communityGalleryImageId
|
string
|
De unieke id van de communitygalerie opgegeven voor vm-implementatie. Dit kan worden opgehaald uit de get-aanroep van de communitygalerieafbeelding.
|
|
exactVersion
|
string
|
Hiermee geeft u de decimale getallen op, de versie van de platforminstallatiekopieën of marketplace-installatiekopieën die worden gebruikt om de virtuele machine te maken. Dit alleen-lezen veld verschilt van 'version', alleen als de waarde die is opgegeven in het veld 'version' 'latest' is.
|
|
id
|
string
|
Resource-id
|
|
offer
|
string
|
Hiermee geeft u de aanbieding op van de platforminstallatiekopieën of marketplace-installatiekopieën die worden gebruikt om de virtuele machine te maken.
|
|
publisher
|
string
|
De uitgever van de installatiekopieën.
|
|
sharedGalleryImageId
|
string
|
De unieke id van de gedeelde galerie-installatiekopieën opgegeven voor vm-implementatie. Dit kan worden opgehaald uit de get-aanroep van de installatiekopieën in de gedeelde galerie.
|
|
sku
|
string
|
De installatiekopieën-SKU.
|
|
version
|
string
|
Hiermee geeft u de versie van de platforminstallatiekopieën of marketplace-installatiekopieën op die worden gebruikt om de virtuele machine te maken. De toegestane indelingen zijn Major.Minor.Build of 'latest'. Primaire, secundaire en build zijn decimale getallen. Geef 'nieuwste' op om de nieuwste versie van een installatiekopieën te gebruiken die beschikbaar is tijdens de implementatie. Zelfs als u 'nieuwste' gebruikt, wordt de VM-installatiekopie niet automatisch bijgewerkt na de implementatietijd, zelfs niet als er een nieuwe versie beschikbaar is. Gebruik het veld 'version' niet voor de implementatie van galerieafbeeldingen, de galerie-installatiekopieën moeten altijd het veld Id gebruiken voor implementatie, als u de meest recente versie van de galerie-installatiekopieën wilt gebruiken, stelt u '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/galleries/{galleryName}/images/{imageName}' in het veld Id in zonder versie-invoer.
|
InnerError
Object
Interne foutdetails.
| Name |
Type |
Description |
|
errordetail
|
string
|
Het interne foutbericht of de uitzonderingsdump.
|
|
exceptiontype
|
string
|
Het uitzonderingstype.
|
InstanceViewStatus
Object
Status van exemplaarweergave.
| Name |
Type |
Description |
|
code
|
string
|
De statuscode.
|
|
displayStatus
|
string
|
Het korte lokaliseerbare label voor de status.
|
|
level
|
StatusLevelTypes
|
De niveaucode.
|
|
message
|
string
|
Het gedetailleerde statusbericht, inclusief voor waarschuwingen en foutberichten.
|
|
time
|
string
(date-time)
|
Het tijdstip van de status.
|
InterconnectBlockProfile
Object
De parameters van een Interconnect Block Profile.
| Name |
Type |
Description |
|
interconnectBlock
|
ApiEntityReference
|
Specificeert de Interconnect Block resource ID die gebruikt moet worden voor het toewijzen van de Virtual Machine of Scale Set VM-instanties, mits er voldoende capaciteit is gereserveerd.
|
InterconnectGroupProfile
Object
Specificeert het interconnect-groepprofiel voor een virtuele machine, gebruikt om de VM te koppelen aan een interconnect-groep en subgroepen.
| Name |
Type |
Description |
|
interconnectGroup
|
SubResource
|
Verwijs naar de interconnect-groepresource.
|
|
subgroups
|
SubResource[]
|
De lijst van subgroepreferenties binnen de interconnectgroep.
|
InterconnectInstanceView
Object
De details van de Interconnect Block-instantie voor een Virtual Machine of Scale Set VM-instantie.
| Name |
Type |
Description |
|
interconnectSubgroupId
|
string
|
De ID (GUID) van de Interconnect-subgroep waarin de virtuele machine werd geplaatst.
|
IPVersions
Opsomming
Vanaf Api-Version 2017-03-30 wordt aangegeven of de specifieke ipconfiguratie IPv4 of IPv6 is. De standaardwaarde wordt gebruikt als IPv4. Mogelijke waarden zijn: 'IPv4' en 'IPv6'.
| Waarde |
Description |
|
IPv4
|
|
|
IPv6
|
|
KeyVaultKeyReference
Object
Beschrijft een verwijzing naar Key Vault-sleutel
| Name |
Type |
Description |
|
keyUrl
|
string
|
De URL die verwijst naar een sleutelversleutelingssleutel in Key Vault.
|
|
sourceVault
|
SubResource
|
De relatieve URL van de sleutelkluis die de sleutel bevat.
|
KeyVaultSecretReference
Object
Beschrijft een verwijzing naar Key Vault-geheim
| Name |
Type |
Description |
|
secretUrl
|
string
|
De URL die verwijst naar een geheim in een Sleutelkluis.
|
|
sourceVault
|
SubResource
|
De relatieve URL van de sleutelkluis die het geheim bevat.
|
LastPatchInstallationSummary
Object
Beschrijft de eigenschappen van de laatst geïnstalleerde patchsamenvatting.
| Name |
Type |
Description |
|
error
|
ApiError
|
De fouten die zijn opgetreden tijdens de uitvoering van de bewerking. De detailarray bevat de lijst ervan.
|
|
excludedPatchCount
|
integer
(int32)
|
Het aantal beschikbare patches, maar expliciet uitgesloten door een door de klant opgegeven uitsluitingslijst.
|
|
failedPatchCount
|
integer
(int32)
|
Het aantal patches waarvoor de installatie is mislukt.
|
|
installationActivityId
|
string
|
De activiteit-id van de bewerking die dit resultaat heeft opgeleverd. Het wordt gebruikt om te correleren tussen CRP- en extensielogboeken.
|
|
installedPatchCount
|
integer
(int32)
|
Het aantal patches dat is geïnstalleerd.
|
|
lastModifiedTime
|
string
(date-time)
|
Het UTC-tijdstempel wanneer de bewerking begon.
|
|
maintenanceWindowExceeded
|
boolean
|
Beschrijft of de bewerking onvoldoende tijd heeft voordat alle beoogde acties zijn voltooid
|
|
notSelectedPatchCount
|
integer
(int32)
|
Het aantal beschikbare patches, maar niet wordt geïnstalleerd omdat deze niet overeenkomt met een classificatie- of opnamelijstvermelding.
|
|
pendingPatchCount
|
integer
(int32)
|
Het aantal beschikbare patches dat naar verwachting tijdens de installatie van de patch wordt geïnstalleerd.
|
|
startTime
|
string
(date-time)
|
Het UTC-tijdstempel wanneer de bewerking begon.
|
|
status
|
PatchOperationStatus
|
De algehele succes- of mislukkingsstatus van de operatie. Het blijft "InProgress" totdat de bewerking is voltooid. Op dat moment wordt het "Onbekend", "Mislukt", "Geslaagd" of "VoltooidMetWaarschuwingen".
|
LinuxConfiguration
Object
Hiermee geeft u de linux-besturingssysteeminstellingen op de virtuele machine. Zie Linux op Azure-Endorsed Distributiesvoor een lijst met ondersteunde Linux-distributies.
| Name |
Type |
Description |
|
disablePasswordAuthentication
|
boolean
|
Hiermee geeft u op of wachtwoordverificatie moet worden uitgeschakeld.
|
|
enableVMAgentPlatformUpdates
|
boolean
|
Geeft aan of VMAgent-platformupdates zijn ingeschakeld voor de virtuele Linux-machine. De standaardwaarde is onwaar.
|
|
patchSettings
|
LinuxPatchSettings
|
[Preview-functie] Hiermee geeft u instellingen met betrekking tot VM-gastpatching op Linux.
|
|
provisionVMAgent
|
boolean
|
Hiermee wordt aangegeven of de virtuele-machineagent moet worden ingericht op de virtuele machine. Wanneer deze eigenschap niet is opgegeven in de hoofdtekst van de aanvraag, is het standaardgedrag ingesteld op waar. Dit zorgt ervoor dat de VM-agent op de VIRTUELE machine is geïnstalleerd, zodat extensies later aan de VIRTUELE machine kunnen worden toegevoegd.
|
|
ssh
|
SshConfiguration
|
Hiermee geeft u de ssh-sleutelconfiguratie voor een Linux-besturingssysteem.
|
LinuxPatchAssessmentMode
Opsomming
Hiermee geeft u de modus van vm-gastpatchevaluatie voor de virtuele IaaS-machine.
Mogelijke waarden zijn:
ImageDefault-: u bepaalt de timing van patchevaluaties op een virtuele machine.
AutomaticByPlatform - Het platform activeert periodieke patchevaluaties. De eigenschap provisionVMAgent moet waar zijn.
| Waarde |
Description |
|
ImageDefault
|
|
|
AutomaticByPlatform
|
|
LinuxPatchSettings
Object
Hiermee geeft u instellingen met betrekking tot VM-gastpatching op Linux.
| Name |
Type |
Description |
|
assessmentMode
|
LinuxPatchAssessmentMode
|
Hiermee geeft u de modus van vm-gastpatchevaluatie voor de virtuele IaaS-machine.
Mogelijke waarden zijn:
ImageDefault-: u bepaalt de timing van patchevaluaties op een virtuele machine.
AutomaticByPlatform - Het platform activeert periodieke patchevaluaties. De eigenschap provisionVMAgent moet waar zijn.
|
|
automaticByPlatformSettings
|
LinuxVMGuestPatchAutomaticByPlatformSettings
|
Hiermee geeft u aanvullende instellingen voor patchmodus AutomaticByPlatform in VM-gastpatching op Linux.
|
|
patchMode
|
LinuxVMGuestPatchMode
|
Hiermee geeft u de modus van VM-gastpatching naar virtuele IaaS-machine of virtuele machines die zijn gekoppeld aan virtuele-machineschaalset met OrchestrationMode als Flexibel.
Mogelijke waarden zijn:
ImageDefault : de standaardpatchingconfiguratie van de virtuele machine wordt gebruikt.
AutomaticByPlatform : de virtuele machine wordt automatisch bijgewerkt door het platform. De eigenschap provisionVMAgent moet waar zijn
|
Opsomming
Hiermee geeft u de instelling voor opnieuw opstarten voor alle installatiebewerkingen van de AutomaticByPlatform-patch.
| Waarde |
Description |
|
Unknown
|
|
|
IfRequired
|
|
|
Never
|
|
|
Always
|
|
Object
Hiermee geeft u aanvullende instellingen op die moeten worden toegepast wanneer de patchmodus AutomaticByPlatform is geselecteerd in de Instellingen voor Linux-patches.
| Name |
Type |
Description |
|
bypassPlatformSafetyChecksOnUserSchedule
|
boolean
|
Stelt de klant in staat patches te plannen zonder onbedoelde upgrades
|
|
rebootSetting
|
LinuxVMGuestPatchAutomaticByPlatformRebootSetting
|
Hiermee geeft u de instelling voor opnieuw opstarten voor alle installatiebewerkingen van de AutomaticByPlatform-patch.
|
LinuxVMGuestPatchMode
Opsomming
Hiermee geeft u de modus van VM-gastpatching naar virtuele IaaS-machine of virtuele machines die zijn gekoppeld aan virtuele-machineschaalset met OrchestrationMode als Flexibel.
Mogelijke waarden zijn:
ImageDefault : de standaardpatchingconfiguratie van de virtuele machine wordt gebruikt.
AutomaticByPlatform : de virtuele machine wordt automatisch bijgewerkt door het platform. De eigenschap provisionVMAgent moet waar zijn
| Waarde |
Description |
|
ImageDefault
|
|
|
AutomaticByPlatform
|
|
MaintenanceOperationResultCodeTypes
Opsomming
De resultaatcode van de laatste onderhoudsbewerking.
| Waarde |
Description |
|
None
|
|
|
RetryLater
|
|
|
MaintenanceAborted
|
|
|
MaintenanceCompleted
|
|
MaintenanceRedeployStatus
Object
Onderhoudsbewerkingsstatus.
| Name |
Type |
Description |
|
isCustomerInitiatedMaintenanceAllowed
|
boolean
|
Waar, als de klant onderhoud mag uitvoeren.
|
|
lastOperationMessage
|
string
|
Bericht geretourneerd voor de laatste onderhoudsbewerking.
|
|
lastOperationResultCode
|
MaintenanceOperationResultCodeTypes
|
De resultaatcode van de laatste onderhoudsbewerking.
|
|
maintenanceWindowEndTime
|
string
(date-time)
|
Eindtijd voor het onderhoudsvenster.
|
|
maintenanceWindowStartTime
|
string
(date-time)
|
Begintijd voor het onderhoudsvenster.
|
|
preMaintenanceWindowEndTime
|
string
(date-time)
|
Eindtijd voor het venster Voor onderhoud.
|
|
preMaintenanceWindowStartTime
|
string
(date-time)
|
Begintijd voor het venster Voor onderhoud.
|
ManagedDiskParameters
Object
De parameters van een beheerde schijf.
| Name |
Type |
Description |
|
additionalDiskProperties
|
AdditionalDiskProperties
|
Specificeert aanvullende eigenschappen voor de beheerde schijf die kunnen worden ingesteld op het moment van impliciete creatie van de schijf. Deze eigenschap wordt niet vastgelegd voor Restore Points.
|
|
diskEncryptionSet
|
DiskEncryptionSetParameters
|
Hiermee geeft u de resource-id van de door de klant beheerde schijfversleutelingsset voor de beheerde schijf op.
|
|
id
|
string
|
Resource-id
|
|
securityProfile
|
VMDiskSecurityProfile
|
Hiermee geeft u het beveiligingsprofiel voor de beheerde schijf.
|
|
storageAccountType
|
StorageAccountTypes
|
Hiermee geeft u het type opslagaccount voor de beheerde schijf. OPMERKING: UltraSSD_LRS kan alleen worden gebruikt met gegevensschijven, deze kan niet worden gebruikt met besturingssysteemschijf.
|
ManagedDiskProperties
Object
Specificeert de eigenschappen van een beheerde schijf die kunnen worden ingesteld op het moment van impliciete creatie van de schijf.
| Name |
Type |
Description |
|
availabilityPolicy
|
DiskAvailabilityPolicy
|
In het geval van een beschikbaarheids- of verbindingsprobleem met de schijf, specificeer dan het gedrag van je VM.
|
|
burstingEnabled
|
boolean
|
Stel in op True om bursting mogelijk te maken buiten het ingerichte prestatiedoel van de schijf. Bursting is standaard uitgeschakeld. Is niet van toepassing op Ultra-schijven.
|
|
diskAccessId
|
string
|
Azure resource ID van de DiskAccess-resource voor het gebruik van private endpoints op disks.
|
|
diskIOPSReadOnly
|
integer
(int64)
|
Het totale aantal IOPS dat wordt toegestaan voor alle VM's die de gedeelde schijf koppelen als ReadOnly. Eén bewerking kan worden overgedragen tussen 4k en 256k bytes.
|
|
diskMBpsReadOnly
|
integer
(int64)
|
De totale doorvoer (MBps) die wordt toegestaan voor alle VM's die de gedeelde schijf koppelen als ReadOnly. MBps betekent miljoenen bytes per seconde- MB maakt hier gebruik van de ISO-notatie, van bevoegdheden van 10.
|
|
logicalSectorSize
|
integer
(int32)
|
Logische sectorgrootte in bytes voor Ultra Disks. Ondersteunde waarden zijn 512 en 4096. 4096 is de standaardwaarde.
|
|
maxShares
|
integer
(int32)
minimum: 1
|
Het maximum aantal virtuele machines dat tegelijkertijd aan de schijf kan worden gekoppeld. De waarde groter dan één geeft een schijf aan die tegelijkertijd op meerdere VM's kan worden gekoppeld. Geldt alleen voor datadisks.
|
|
networkAccessPolicy
|
NetworkAccessPolicy
|
Beleid voor toegang tot de schijf via het netwerk.
|
|
optimizedForFrequentAttach
|
boolean
|
Het instellen van deze eigenschap op true verbetert de betrouwbaarheid en prestaties van dataschijven die vaak (meer dan 5 keer per dag) van de ene virtuele machine worden losgekoppeld en aan een andere worden gekoppeld. Deze eigenschap mag niet worden ingesteld voor schijven die niet vaak zijn losgekoppeld en gekoppeld, omdat de schijven niet overeenkomen met het foutdomein van de virtuele machine.
|
|
performancePlus
|
boolean
|
Stel deze vlag in op True om een boost te krijgen op het prestatiedoel van de schijf die is geïmplementeerd. Deze vlag kan alleen worden ingesteld op de aanmaaktijd van de schijf en kan niet worden uitgeschakeld nadat deze is ingeschakeld.
|
|
tier
|
string
|
Prestatielaag van de schijf (bijv. P4, S10) zoals hier beschreven: https://azure.microsoft.com/en-us/pricing/details/managed-disks/. Is niet van toepassing op Ultra-schijven.
|
Mode
Opsomming
Hiermee geeft u de modus op waarop ProxyAgent wordt uitgevoerd als de functie is ingeschakeld. ProxyAgent begint met controleren of bewaken, maar dwingt geen toegangsbeheer af over aanvragen voor hosteindpunten in de controlemodus, terwijl in de modus Afdwingen het toegangsbeheer wordt afgedwongen. De standaardwaarde is de modus Afdwingen.
| Waarde |
Description |
|
Audit
|
|
|
Enforce
|
|
Modes
Opsomming
Hiermee geeft u de uitvoeringsmodus. In de controlemodus fungeert het systeem alsof het het toegangsbeheerbeleid afdwingt, inclusief het verzenden van toegangsontkenningsvermeldingen in de logboeken, maar het weigert geen aanvragen voor hosteindpunten. In de modus Afdwingen dwingt het systeem het toegangsbeheer af en is het de aanbevolen bewerkingsmodus.
| Waarde |
Description |
|
Audit
|
|
|
Enforce
|
|
|
Disabled
|
|
NetworkAccessPolicy
Opsomming
Beleid voor toegang tot de schijf via het netwerk.
| Waarde |
Description |
|
AllowAll
|
De schijf kan worden geëxporteerd of geüpload vanaf elk netwerk.
|
|
AllowPrivate
|
De schijf kan worden geëxporteerd of geüpload met behulp van de privé-eindpunten van een DiskAccess-bron.
|
|
DenyAll
|
De schijf kan niet worden geëxporteerd.
|
NetworkApiVersion
Opsomming
hiermee geeft u de Microsoft.Network API-versie op die wordt gebruikt bij het maken van netwerkresources in de netwerkinterfaceconfiguraties
| Waarde |
Description |
|
2020-11-01
|
|
|
2022-11-01
|
|
NetworkInterfaceAuxiliaryMode
Opsomming
Hiermee geeft u op of de hulpmodus is ingeschakeld voor de netwerkinterfaceresource.
| Waarde |
Description |
|
None
|
|
|
AcceleratedConnections
|
|
|
Floating
|
|
NetworkInterfaceAuxiliarySku
Opsomming
Hiermee geeft u op of de hulp-sku is ingeschakeld voor de netwerkinterfaceresource.
| Waarde |
Description |
|
None
|
|
|
A1
|
|
|
A2
|
|
|
A4
|
|
|
A8
|
|
NetworkInterfaceReference
Object
Beschrijft een netwerkinterfacereferentie.
| Name |
Type |
Description |
|
id
|
string
|
Resource-id
|
|
properties.deleteOption
|
DeleteOptions
|
Opgeven wat er gebeurt met de netwerkinterface wanneer de VIRTUELE machine wordt verwijderd
|
|
properties.primary
|
boolean
|
Hiermee geeft u de primaire netwerkinterface op voor het geval de virtuele machine meer dan 1 netwerkinterface heeft.
|
NetworkProfile
Object
Hiermee geeft u de netwerkinterfaces of de netwerkconfiguratie van de virtuele machine.
| Name |
Type |
Description |
|
interconnectGroupProfile
|
InterconnectGroupProfile
|
Specificeert het interconnect-groepprofiel dat aan de virtuele machine gekoppeld moet worden. Minimale api-versie: 2026-03-01.
|
|
networkApiVersion
|
NetworkApiVersion
|
hiermee geeft u de Microsoft.Network API-versie op die wordt gebruikt bij het maken van netwerkresources in de netwerkinterfaceconfiguraties
|
|
networkInterfaceConfigurations
|
VirtualMachineNetworkInterfaceConfiguration[]
|
Hiermee geeft u de netwerkconfiguraties op die worden gebruikt om de virtuele-machinenetwerkresources te maken.
|
|
networkInterfaces
|
NetworkInterfaceReference[]
|
Hiermee geeft u de lijst met resource-id's voor de netwerkinterfaces die zijn gekoppeld aan de virtuele machine.
|
OperatingSystemTypes
Opsomming
Met deze eigenschap kunt u het type besturingssysteem opgeven dat op de schijf is opgenomen als u een virtuele machine maakt op basis van een aangepaste installatiekopie. Mogelijke waarden zijn: Windows,Linux.
| Waarde |
Description |
|
Windows
|
|
|
Linux
|
|
OSDisk
Object
Hiermee geeft u informatie op over de besturingssysteemschijf die wordt gebruikt door de virtuele machine. Zie Over schijven en VHD's voor virtuele Azure-machinesvoor meer informatie over schijven.
| Name |
Type |
Description |
|
caching
|
CachingTypes
|
Hiermee geeft u de cachevereisten op. Mogelijke waarden zijn: None,ReadOnlyReadWrite. Het standaardgedrag is: Geen voor Standard-opslag. ReadOnly voor Premium-opslag.
|
|
createOption
|
DiskCreateOptionTypes
|
Hiermee geeft u op hoe de schijf van de virtuele machine moet worden gemaakt. Mogelijke waarden zijn Koppelen: Deze waarde wordt gebruikt wanneer u een gespecialiseerde schijf gebruikt om de virtuele machine te maken.
FromImage: Deze waarde wordt gebruikt wanneer u een installatiekopie gebruikt om de virtuele machine te maken. Als u een platforminstallatiekopie gebruikt, moet u ook het element imageReference gebruiken dat hierboven wordt beschreven. Als u een marketplace-installatiekopieën gebruikt, moet u ook het eerder beschreven planelement gebruiken.
|
|
deleteOption
|
DiskDeleteOptionTypes
|
Hiermee geeft u op of de besturingssysteemschijf moet worden verwijderd of losgekoppeld bij het verwijderen van de virtuele machine. Mogelijke waarden zijn: Verwijderen. Als deze waarde wordt gebruikt, wordt de besturingssysteemschijf verwijderd wanneer de VIRTUELE machine wordt verwijderd. Loskoppelen. Als deze waarde wordt gebruikt, blijft de besturingssysteemschijf behouden nadat de VIRTUELE machine is verwijderd. De standaardwaarde is ingesteld op Loskoppelen. Voor een tijdelijke besturingssysteemschijf is de standaardwaarde ingesteld op Verwijderen. De gebruiker kan de verwijderoptie voor een tijdelijke besturingssysteemschijf niet wijzigen.
|
|
diffDiskSettings
|
DiffDiskSettings
|
Hiermee geeft u de tijdelijke schijfinstellingen voor de besturingssysteemschijf die door de virtuele machine wordt gebruikt.
|
|
diskSizeGB
|
integer
(int32)
|
Hiermee geeft u de grootte van een lege gegevensschijf in gigabytes. Dit element kan worden gebruikt om de grootte van de schijf in een installatiekopieën van een virtuele machine te overschrijven. De eigenschap diskSizeGB is het aantal bytes x 1024^3 voor de schijf en de waarde mag niet groter zijn dan 1023.
|
|
encryptionSettings
|
DiskEncryptionSettings
|
Hiermee geeft u de versleutelingsinstellingen voor de besturingssysteemschijf. Minimale API-versie: 2015-06-15.
|
|
image
|
VirtualHardDisk
|
De virtuele harde schijf van de brongebruiker. De virtuele harde schijf wordt gekopieerd voordat deze aan de virtuele machine wordt gekoppeld. Als SourceImage is opgegeven, mag de virtuele doelschijf niet bestaan.
|
|
managedDisk
|
ManagedDiskParameters
|
De parameters van de beheerde schijf.
|
|
name
|
string
|
De naam van de schijf.
|
|
osType
|
OperatingSystemTypes
|
Met deze eigenschap kunt u het type besturingssysteem opgeven dat is opgenomen in de schijf als u een virtuele machine maakt op basis van een gebruikersinstallatiekopie of een gespecialiseerde VHD. Mogelijke waarden zijn: Windows,Linux.
|
|
storageFaultDomainAlignment
|
StorageFaultDomainAlignmentType
|
Specificeert het type uitlijning van het opslagfoutdomein voor de schijf.
|
|
vhd
|
VirtualHardDisk
|
De virtuele harde schijf.
|
|
writeAcceleratorEnabled
|
boolean
|
Hiermee geeft u op of writeAccelerator moet worden ingeschakeld of uitgeschakeld op de schijf.
|
OSImageNotificationProfile
Object
| Name |
Type |
Description |
|
enable
|
boolean
|
Hiermee geeft u op of de geplande gebeurtenis van de besturingssysteeminstallatiekopieën is ingeschakeld of uitgeschakeld.
|
|
notBeforeTimeout
|
string
|
De tijdsduur waarop een virtuele machine wordt hersteld of dat het besturingssysteem wordt bijgewerkt, moet mogelijk de geplande gebeurtenis van de installatiekopie van het besturingssysteem goedkeuren voordat de gebeurtenis automatisch wordt goedgekeurd (time-out). De configuratie is opgegeven in ISO 8601-indeling en de waarde moet 15 minuten zijn (PT15M)
|
OSProfile
Object
Hiermee geeft u de besturingssysteeminstellingen voor de virtuele machine. Sommige instellingen kunnen niet worden gewijzigd zodra de VIRTUELE machine is ingericht.
| Name |
Type |
Description |
|
adminPassword
|
string
(password)
|
Hiermee geeft u het wachtwoord van het beheerdersaccount.
Minimale lengte (Windows): 8 tekens
Minimale lengte (Linux): 6 tekens
Maximale lengte (Windows): 123 tekens
Maximale lengte (Linux): 72 tekens
Complexiteitsvereisten: aan 3 van de 4 onderstaande voorwaarden moet worden voldaan Heeft lagere tekens Bevat bovenliggende tekens Heeft een cijfer Heeft een speciaal teken (Regex-overeenkomst [\W_])
Niet-toegestane waarden: "abc@123", "P@$$w 0rd", "P@ssw0rd", "P@ssword123", "Pa$$word", "pass@word1", "Wachtwoord!", "Wachtwoord1", "Wachtwoord22", "iloveyou!"
Zie De extern bureaublad-service of het aanmeldingswachtwoord opnieuw instellen in een Windows-VM voor het opnieuw instellen van het wachtwoord.
Zie Gebruikers, SSH beheren en schijven controleren of herstellen op virtuele Azure Linux-machines met behulp van de VMAccess-extensie voor het opnieuw instellen van het hoofdwachtwoord
|
|
adminUsername
|
string
|
Hiermee geeft u de naam van het beheerdersaccount.
Deze eigenschap kan niet worden bijgewerkt nadat de virtuele machine is gemaakt.
beperking voor alleen Windows: kan niet eindigen op '.'
niet-toegestane waarden: 'administrator', 'admin', 'user', 'user1', 'test', 'user2', 'test1', 'user3', 'admin1', "1", "123", "a", "actuser", "adm", "admin2", "aspnet", "backup", "console", "david", "guest", "john", "owner", "root", "server", "sql", "support", "support_388945a0", "sys", "test2", "test3", "user4", "user5".
Minimale lengte (Linux): 1 teken
Maximale lengte (Linux): 64 tekens
Maximale lengte (Windows): 20 tekens.
|
|
allowExtensionOperations
|
boolean
|
Hiermee geeft u op of uitbreidingsbewerkingen moeten worden toegestaan op de virtuele machine. Dit kan alleen worden ingesteld op False wanneer er geen extensies aanwezig zijn op de virtuele machine.
|
|
computerName
|
string
|
Hiermee geeft u de naam van het host-besturingssysteem van de virtuele machine. Deze naam kan niet worden bijgewerkt nadat de virtuele machine is gemaakt.
Maximale lengte (Windows): 15 tekens.
Maximale lengte (Linux): 64 tekens. Zie implementatierichtlijnen voor Azure-infrastructuurservicesvoor naamconventies en -beperkingen.
|
|
customData
|
string
|
Hiermee geeft u een met base 64 gecodeerde tekenreeks van aangepaste gegevens op. De met base 64 gecodeerde tekenreeks wordt gedecodeerd naar een binaire matrix die wordt opgeslagen als een bestand op de virtuele machine. De maximale lengte van de binaire matrix is 65535 bytes. Opmerking: geef geen geheimen of wachtwoorden door in de eigenschap customData. Deze eigenschap kan niet worden bijgewerkt nadat de virtuele machine is gemaakt. De eigenschap 'customData' wordt doorgegeven aan de virtuele machine die als bestand moet worden opgeslagen. Zie Aangepaste gegevens op Virtuele Azure-machinesvoor meer informatie. Zie Cloud-init gebruiken om een Virtuele Linux-machine aan te passen tijdens het maken vanvoor het gebruik van cloud-init.
|
|
linuxConfiguration
|
LinuxConfiguration
|
Hiermee geeft u de linux-besturingssysteeminstellingen op de virtuele machine. Zie Linux op Azure-Endorsed Distributiesvoor een lijst met ondersteunde Linux-distributies.
|
|
requireGuestProvisionSignal
|
boolean
|
Optionele eigenschap die moet worden ingesteld op Waar of weggelaten.
|
|
secrets
|
VaultSecretGroup[]
|
Hiermee geeft u een set certificaten op die op de virtuele machine moeten worden geïnstalleerd. Als u certificaten op een virtuele machine wilt installeren, wordt u aangeraden de extensie van de virtuele Azure Key Vault-machine voor Linux- of de virtuele Machine-extensie van Azure Key Vault voor Windowste gebruiken.
|
|
windowsConfiguration
|
WindowsConfiguration
|
Hiermee geeft u windows-besturingssysteeminstellingen op de virtuele machine.
|
PassNames
Opsomming
| Waarde |
Description |
|
OobeSystem
|
|
PatchOperationStatus
Opsomming
De algehele succes- of mislukkingsstatus van de operatie. Het blijft "InProgress" totdat de bewerking is voltooid. Op dat moment wordt het "Onbekend", "Mislukt", "Geslaagd" of "VoltooidMetWaarschuwingen".
| Waarde |
Description |
|
Unknown
|
|
|
InProgress
|
|
|
Failed
|
|
|
Succeeded
|
|
|
CompletedWithWarnings
|
|
PatchSettings
Object
Hiermee geeft u instellingen met betrekking tot VM-gastpatching in Windows.
| Name |
Type |
Description |
|
assessmentMode
|
WindowsPatchAssessmentMode
|
Hiermee geeft u de modus van vm-gastpatchevaluatie voor de virtuele IaaS-machine.
Mogelijke waarden zijn:
ImageDefault-: u bepaalt de timing van patchevaluaties op een virtuele machine.
AutomaticByPlatform - Het platform activeert periodieke patchevaluaties. De eigenschap provisionVMAgent moet waar zijn.
|
|
automaticByPlatformSettings
|
WindowsVMGuestPatchAutomaticByPlatformSettings
|
Hiermee geeft u aanvullende instellingen voor patchmodus AutomaticByPlatform in VM-gastpatching in Windows.
|
|
enableHotpatching
|
boolean
|
Hiermee kunnen klanten hun Virtuele Azure-machines patchen zonder dat ze opnieuw hoeven op te starten. Voor enableHotpatching moet de 'provisionVMAgent' worden ingesteld op true en moet patchMode worden ingesteld op 'AutomaticByPlatform'.
|
|
patchMode
|
WindowsVMGuestPatchMode
|
Hiermee geeft u de modus van VM-gastpatching naar virtuele IaaS-machine of virtuele machines die zijn gekoppeld aan virtuele-machineschaalset met OrchestrationMode als Flexibel.
Mogelijke waarden zijn:
Handmatig: u beheert de toepassing van patches op een virtuele machine. U doet dit door patches handmatig toe te passen in de VIRTUELE machine. In deze modus worden automatische updates uitgeschakeld; de eigenschap WindowsConfiguration.enableAutomaticUpdates moet onwaar zijn
AutomaticByOS : de virtuele machine wordt automatisch bijgewerkt door het besturingssysteem. De eigenschap WindowsConfiguration.enableAutomaticUpdates moet waar zijn.
AutomaticByPlatform : de virtuele machine wordt automatisch bijgewerkt door het platform. De eigenschappen provisionVMAgent en WindowsConfiguration.enableAutomaticUpdates moeten waar zijn
|
Placement
Object
Beschrijft de door de gebruiker gedefinieerde beperkingen voor de plaatsing van resourcehardware.
| Name |
Type |
Description |
|
excludeZones
|
string[]
|
Deze eigenschap vormt een aanvulling op de eigenschap zonePlacementPolicy. Als 'zonePlacementPolicy' is ingesteld op 'Any'/'Auto', mag de beschikbaarheidszone die door het systeem is geselecteerd, niet voorkomen in de lijst met beschikbaarheidszones die zijn doorgegeven met 'excludeZones'. Als 'excludeZones' niet is opgegeven, worden alle beschikbaarheidszones in de regio in aanmerking genomen voor selectie.
|
|
includeZones
|
string[]
|
Deze eigenschap vormt een aanvulling op de eigenschap zonePlacementPolicy. Als 'zonePlacementPolicy' is ingesteld op 'Any'/'Auto', moet de beschikbaarheidszone die door het systeem is geselecteerd, aanwezig zijn in de lijst met beschikbaarheidszones die zijn doorgegeven met 'includeZones'. Als 'includeZones' niet is opgegeven, worden alle beschikbaarheidszones in de regio in aanmerking genomen voor selectie.
|
|
zonePlacementPolicy
|
ZonePlacementPolicyType
|
Hiermee geeft u het beleid op voor de plaatsing van de resource in de beschikbaarheidszone. Mogelijke waarden zijn: Alle (gebruikt voor virtuele machines), Auto (gebruikt voor virtuele-machineschaalsets) - Een beschikbaarheidszone wordt automatisch door het systeem gekozen als onderdeel van het maken van resources.
|
Plan
Object
Hiermee geeft u informatie op over de marketplace-installatiekopieën die worden gebruikt om de virtuele machine te maken. Dit element wordt alleen gebruikt voor Marketplace-installatiekopieën. Voordat u een Marketplace-installatiekopieën van een API kunt gebruiken, moet u de installatiekopieën inschakelen voor programmatisch gebruik. Zoek in Azure Portal de marketplace-installatiekopieën die u wilt gebruiken en klik vervolgens op Programmatisch wilt implementeren, Aan de slag ->. Voer de vereiste gegevens in en klik vervolgens op Opslaan.
| Name |
Type |
Description |
|
name
|
string
|
De plan-id.
|
|
product
|
string
|
Hiermee geeft u het product van de installatiekopieën van de marketplace. Dit is dezelfde waarde als Offer onder het element imageReference.
|
|
promotionCode
|
string
|
De promotiecode.
|
|
publisher
|
string
|
De uitgever-id.
|
ProcessorMode
Opsomming
Specificeert het processorfrequentiegedrag voor de virtuele machine. Bekijk elk lid voor het gedrag dat het controleert.
| Waarde |
Description |
|
Deterministic
|
Zorgt voor voorspelbare en consistente processorfrequentie op het basis-/nominale niveau. Turbo/Boost is uitgeschakeld.
|
|
Opportunistic
|
Maakt hogere frequentie-bursts mogelijk wanneer thermische en vermogenshoofdruimte het toelaten.
|
ProtocolTypes
Opsomming
Hiermee geeft u het protocol van WinRM-listener. Mogelijke waarden zijn: http,https.
| Waarde |
Description |
|
Http
|
|
|
Https
|
|
ProxyAgentSettings
Object
Hiermee geeft u ProxyAgent-instellingen voor de virtuele machine of virtuele-machineschaalset. Minimale API-versie: 2023-09-01.
| Name |
Type |
Description |
|
addProxyAgentExtension
|
boolean
|
Geef op of de ProxyAgent-extensie impliciet moet worden geïnstalleerd. Deze optie is momenteel alleen van toepassing op Linux OS.
|
|
enabled
|
boolean
|
Hiermee geeft u op of de functie ProxyAgent moet worden ingeschakeld op de virtuele machine of virtuele-machineschaalset.
|
|
imds
|
HostEndpointSettings
|
Hiermee geeft u de IMDS-eindpuntinstellingen op tijdens het maken van de virtuele machine of virtuele-machineschaalset. Minimale API-versie: 2024-03-01.
|
|
keyIncarnationId
|
integer
(int32)
|
Verhoog de waarde van deze eigenschap zodat gebruikers de sleutel die wordt gebruikt voor het beveiligen van het communicatiekanaal tussen gast en host opnieuw kunnen instellen.
|
|
mode
|
Mode
|
Hiermee geeft u de modus op waarop ProxyAgent wordt uitgevoerd. Waarschuwing: deze eigenschap is afgeschaft. Geef de modus op onder een bepaalde instelling voor hostendpoint.
|
|
wireServer
|
HostEndpointSettings
|
Hiermee geeft u de instellingen voor wire server-eindpunten op tijdens het maken van de virtuele machine of virtuele-machineschaalset. Minimale API-versie: 2024-03-01.
|
PublicIPAddressSku
Object
Beschrijft de openbare IP-SKU. Deze kan alleen worden ingesteld met OrchestrationMode als Flexible.
PublicIPAddressSkuName
Opsomming
Geef de naam van de openbare IP-SKU op
| Waarde |
Description |
|
Basic
|
|
|
Standard
|
|
PublicIPAddressSkuTier
Opsomming
Openbare IP-SKU-laag opgeven
| Waarde |
Description |
|
Regional
|
|
|
Global
|
|
PublicIPAllocationMethod
Opsomming
Geef het type openbare IP-toewijzing op
| Waarde |
Description |
|
Dynamic
|
|
|
Static
|
|
ResiliencyProfile
Object
Schakelt veerkrachtoplossingen in op de VM. Dit omvat back-up- of rampenhersteloplossingen.
| Name |
Type |
Description |
|
zoneMovement
|
ZoneMovement
|
Zone-bewegingsconfiguratie.
|
ResourceIdentityType
Opsomming
Het type identiteit dat wordt gebruikt voor de virtuele machine. Het type SystemAssigned, UserAssigned bevat zowel een impliciet gemaakte identiteit als een set door de gebruiker toegewezen identiteiten. Met het type None worden alle identiteiten van de virtuele machine verwijderd.
| Waarde |
Description |
|
SystemAssigned
|
|
|
UserAssigned
|
|
|
SystemAssigned, UserAssigned
|
|
|
None
|
|
ScheduledEventsAdditionalPublishingTargets
Object
| Name |
Type |
Description |
|
eventGridAndResourceGraph
|
EventGridAndResourceGraph
|
De configuratieparameters die worden gebruikt bij het maken van de geplande gebeurtenisinstelling eventgridAndResourceGraph.
|
ScheduledEventsPolicy
Object
Hiermee geeft u configuraties op die betrekking hebben op opnieuw implementeren, opnieuw opstarten en ScheduledEventsAdditionalPublishingTargets Scheduled Event.
| Name |
Type |
Description |
|
allInstancesDown
|
AllInstancesDown
|
De configuratieparameters die worden gebruikt bij het maken van geplande gebeurtenisinstellingen van AllInstancesDown.
|
|
scheduledEventsAdditionalPublishingTargets
|
ScheduledEventsAdditionalPublishingTargets
|
De configuratieparameters die worden gebruikt tijdens het publiceren van scheduledEventsAdditionalPublishingTargets.
|
|
userInitiatedReboot
|
UserInitiatedReboot
|
De configuratieparameters die worden gebruikt tijdens het maken van de geplande gebeurtenisinstelling UserInitiatedReboot.
|
|
userInitiatedRedeploy
|
UserInitiatedRedeploy
|
De configuratieparameters die worden gebruikt tijdens het maken van de geplande gebeurtenisinstelling userInitiatedRedeploy.
|
ScheduledEventsProfile
Object
| Name |
Type |
Description |
|
osImageNotificationProfile
|
OSImageNotificationProfile
|
Hiermee geeft u configuraties met betrekking tot geplande gebeurtenissen van de besturingssysteeminstallatiekopieën op.
|
|
terminateNotificationProfile
|
TerminateNotificationProfile
|
Hiermee geeft u configuraties voor geplande gebeurtenissen beëindigen op.
|
SecurityEncryptionTypes
Opsomming
Hiermee geeft u het EncryptionType van de beheerde schijf. Deze is ingesteld op DiskWithVMGuestState voor versleuteling van de beheerde schijf, samen met VMGuestState-blob, VMGuestStateOnly voor versleuteling van alleen de VMGuestState-blob en NonPersistedTPM voor het niet behouden van de firmwarestatus in de VMGuestState-blob..
Opmerking: Deze kan alleen worden ingesteld voor vertrouwelijke VM's.
| Waarde |
Description |
|
VMGuestStateOnly
|
|
|
DiskWithVMGuestState
|
|
|
NonPersistedTPM
|
|
SecurityProfile
Object
Hiermee geeft u de beveiligingsprofielinstellingen voor de virtuele machine of virtuele-machineschaalset op.
| Name |
Type |
Description |
|
encryptionAtHost
|
boolean
|
Deze eigenschap kan worden gebruikt door de gebruiker in de aanvraag om hostversleuteling voor de virtuele machine of virtuele-machineschaalset in of uit te schakelen. Hierdoor wordt de versleuteling ingeschakeld voor alle schijven, inclusief resource-/tijdelijke schijf op de host zelf. Het standaardgedrag is: De versleuteling op de host wordt uitgeschakeld, tenzij deze eigenschap is ingesteld op waar voor de resource.
|
|
encryptionIdentity
|
EncryptionIdentity
|
Hiermee geeft u de beheerde identiteit op die door ADE wordt gebruikt om toegangstoken op te halen voor sleutelkluisbewerkingen.
|
|
proxyAgentSettings
|
ProxyAgentSettings
|
Hiermee geeft u ProxyAgent-instellingen op tijdens het maken van de virtuele machine. Minimale API-versie: 2023-09-01.
|
|
securityType
|
SecurityTypes
|
Hiermee geeft u het SecurityType van de virtuele machine. Deze moet worden ingesteld op een opgegeven waarde om UefiSettings in te schakelen. Het standaardgedrag is: UefiSettings wordt niet ingeschakeld tenzij deze eigenschap is ingesteld en niet Standard is. Indien niet gespecificeerd, wordt Standard geretourneerd vanaf API-versie 2025-11-01.
|
|
uefiSettings
|
UefiSettings
|
Hiermee geeft u de beveiligingsinstellingen op, zoals beveiligd opstarten en vTPM die worden gebruikt tijdens het maken van de virtuele machine. Minimale API-versie: 2020-12-01.
|
SecurityTypes
Opsomming
Specificeert de VM securityType; UefiSettings zijn alleen ingeschakeld wanneer ingesteld op TrustedLaunch of ConfidentialVM, en geven een standaardwaarde terug vanaf API-versie 2025-11-01.
| Waarde |
Description |
|
Standard
|
Geeft een VM aan zonder UEFI-functies zoals SecureBoot of vTPM; als standaardwaarde teruggegeven wanneer securityType niet is gespecificeerd.
|
|
TrustedLaunch
|
|
|
ConfidentialVM
|
|
SettingNames
Opsomming
Hiermee geeft u de naam op van de instelling waarop de inhoud van toepassing is. Mogelijke waarden zijn: FirstLogonCommands en AutoLogon.
| Waarde |
Description |
|
AutoLogon
|
|
|
FirstLogonCommands
|
|
SshConfiguration
Object
SSH-configuratie voor op Linux gebaseerde VM's die worden uitgevoerd in Azure
| Name |
Type |
Description |
|
publicKeys
|
SshPublicKey[]
|
De lijst met openbare SSH-sleutels die worden gebruikt voor verificatie met virtuele Linux-machines.
|
SshPublicKey
Object
Bevat informatie over de openbare SSH-certificaatsleutel en het pad op de Virtuele Linux-machine waarop de openbare sleutel wordt geplaatst.
| Name |
Type |
Description |
|
keyData
|
string
|
Het openbare SSH-sleutelcertificaat dat wordt gebruikt voor verificatie met de virtuele machine via ssh. De sleutel moet ten minste 2048-bits en in ssh-rsa-indeling zijn. Zie [SSH-sleutels maken in Linux en Mac voor Linux-VM's in Azure]https://docs.microsoft.com/azure/virtual-machines/linux/create-ssh-keys-detailed). voor het maken van SSH-sleutels
|
|
path
|
string
|
Hiermee geeft u het volledige pad op de gemaakte VM waarin de openbare SSH-sleutel wordt opgeslagen. Als het bestand al bestaat, wordt de opgegeven sleutel toegevoegd aan het bestand. Voorbeeld: /home/user/.ssh/authorized_keys
|
StatusLevelTypes
Opsomming
De niveaucode.
| Waarde |
Description |
|
Info
|
|
|
Warning
|
|
|
Error
|
|
StorageAccountTypes
Opsomming
Hiermee geeft u het type opslagaccount voor de beheerde schijf. Het opslagaccounttype beheerde besturingssysteemschijf kan alleen worden ingesteld wanneer u de schaalset maakt. OPMERKING: UltraSSD_LRS kan alleen worden gebruikt met gegevensschijven. Het kan niet worden gebruikt met besturingssysteemschijf. Standard_LRS maakt gebruik van Standard HDD. StandardSSD_LRS maakt gebruik van Standard SSD. Premium_LRS maakt gebruik van Premium SSD. UltraSSD_LRS maakt gebruik van Ultra disk. Premium_ZRS maakt gebruik van premium SSD-zone-redundante opslag. StandardSSD_ZRS maakt gebruik van zone-redundante opslag met Standard SSD. Raadpleeg voor meer informatie over schijven die worden ondersteund voor Virtuele Windows-machines https://docs.microsoft.com/azure/virtual-machines/windows/disks-types en raadpleeg voor Virtuele Linux-machines https://docs.microsoft.com/azure/virtual-machines/linux/disks-types
| Waarde |
Description |
|
Standard_LRS
|
|
|
Premium_LRS
|
|
|
StandardSSD_LRS
|
|
|
UltraSSD_LRS
|
|
|
Premium_ZRS
|
|
|
StandardSSD_ZRS
|
|
|
PremiumV2_LRS
|
|
StorageAlignmentStatus
Opsomming
Specificeert de opslaguitlijningsstatus voor de schijf.
| Waarde |
Description |
|
Unaligned
|
De schijf heeft geen mapping van Storage Fault Domain naar Compute Fault Domain. Een enkele storing in het Storage Fault Domain kan alle VM's beïnvloeden die naar dit schijfprofiel verwijzen.
|
|
Aligned
|
De schijf heeft Storage Fault Domain om Fault Domain mapping te berekenen. Storing van het Storage Fault Domain is beperkt tot VM's in één Compute Fault Domain.
|
StorageFaultDomainAlignmentType
Opsomming
Specificeert het type uitlijning van het opslagfoutdomein voor de schijf.
| Waarde |
Description |
|
Aligned
|
Schijfopslagfoutdomeinen worden gekoppeld aan rekenfoutdomeinen. Deployment faalt als de schijf niet genoeg Fault Domains ondersteunt.
|
|
BestEffortAligned
|
Probeer opslagfoutdomeinen te mappen naar berekeningsfoutdomeinen. Schijven zijn niet uitgelijnd als de schijf niet genoeg Foutdomeinen ondersteunt.
|
StorageProfile
Object
Hiermee geeft u de opslaginstellingen voor de schijven van de virtuele machine op.
| Name |
Type |
Description |
|
alignRegionalDisksToVMZone
|
boolean
|
Hiermee geeft u op of de regionale schijven moeten worden uitgelijnd/verplaatst naar de VM-zone. Dit is alleen van toepassing op VM's waarvoor plaatsingseigenschappen zijn ingesteld. Houd er rekening mee dat deze wijziging niet ongedaan kan worden. Minimale API-versie: 2024-11-01.
|
|
dataDisks
|
DataDisk[]
|
Hiermee geeft u de parameters op die worden gebruikt om een gegevensschijf toe te voegen aan een virtuele machine. Zie Over schijven en VHD's voor virtuele Azure-machinesvoor meer informatie over schijven.
|
|
diskApiVersion
|
DiskApiVersion
|
Specificeert de Disk API-versie die wordt gebruikt bij het toepassen van additionalDiskProperties op beheerde schijven. De waarde moet in het formaat YYYY-MM-DD zijn (bijv. "2026-03-02").
|
|
diskControllerType
|
DiskControllerTypes
|
Hiermee geeft u het type schijfcontroller geconfigureerd voor de virtuele machine.
Opmerking: Deze eigenschap wordt ingesteld op het standaardtype schijfcontroller als er geen opgegeven virtuele machine wordt gemaakt met hyperVGeneratie ingesteld op V2 op basis van de mogelijkheden van de besturingssysteemschijf en VM-grootte van de opgegeven minimale API-versie. U moet de toewijzing van de VIRTUELE machine ongedaan maken voordat u het type schijfcontroller bijwerkt, tenzij u de VM-grootte bijwerkt in de VM-configuratie die impliciet de toewijzing ongedaan maakt en de VM opnieuw toewijst. Minimale API-versie: 2022-08-01.
|
|
imageReference
|
ImageReference
|
Hiermee geeft u informatie over de te gebruiken afbeelding. U kunt informatie opgeven over platforminstallatiekopieën, marketplace-installatiekopieën of installatiekopieën van virtuele machines. Dit element is vereist wanneer u een platforminstallatiekopie, marketplace-installatiekopie of installatiekopie van virtuele machines wilt gebruiken, maar niet wordt gebruikt in andere bewerkingen voor het maken.
|
|
osDisk
|
OSDisk
|
Hiermee geeft u informatie op over de besturingssysteemschijf die wordt gebruikt door de virtuele machine. Zie Over schijven en VHD's voor virtuele Azure-machinesvoor meer informatie over schijven.
|
SubResource
Object
| Name |
Type |
Description |
|
id
|
string
|
Resource-id
|
systemData
Object
Metagegevens met betrekking tot het maken en de laatste wijziging van de resource.
| Name |
Type |
Description |
|
createdAt
|
string
(date-time)
|
De tijdstempel van het aanmaken van resources (UTC).
|
|
createdBy
|
string
|
De identiteit die de resource heeft gemaakt.
|
|
createdByType
|
createdByType
|
Het identiteitstype dat de resource heeft gemaakt.
|
|
lastModifiedAt
|
string
(date-time)
|
De tijdstempel van de laatste wijziging van de resource (UTC)
|
|
lastModifiedBy
|
string
|
De identiteit die de resource voor het laatst heeft gewijzigd.
|
|
lastModifiedByType
|
createdByType
|
Het type identiteit dat de resource voor het laatst heeft gewijzigd.
|
TerminateNotificationProfile
Object
| Name |
Type |
Description |
|
enable
|
boolean
|
Hiermee geeft u op of de geplande beëindigingsgebeurtenis is ingeschakeld of uitgeschakeld.
|
|
notBeforeTimeout
|
string
|
Configureerbare tijdsduur waarop een virtuele machine die wordt verwijderd, moet mogelijk de geplande beëindigingsgebeurtenis goedkeuren voordat de gebeurtenis automatisch wordt goedgekeurd (time-out). De configuratie moet worden opgegeven in ISO 8601-indeling, de standaardwaarde is 5 minuten (PT5M)
|
UefiSettings
Object
Hiermee geeft u de beveiligingsinstellingen op, zoals beveiligd opstarten en vTPM die worden gebruikt tijdens het maken van de virtuele machine. Minimale API-versie: 2020-12-01.
| Name |
Type |
Description |
|
secureBootEnabled
|
boolean
|
Hiermee geeft u op of beveiligd opstarten moet worden ingeschakeld op de virtuele machine. Minimale API-versie: 2020-12-01.
|
|
vTpmEnabled
|
boolean
|
Hiermee geeft u op of vTPM moet worden ingeschakeld op de virtuele machine. Minimale API-versie: 2020-12-01.
|
UserInitiatedReboot
Object
Hiermee geeft u gerelateerde configuraties voor geplande gebeurtenissen opnieuw opstarten op.
| Name |
Type |
Description |
|
automaticallyApprove
|
boolean
|
Hiermee geeft u configuraties voor geplande gebeurtenissen opnieuw opstarten op.
|
UserInitiatedRedeploy
Object
Hiermee geeft u gerelateerde configuraties voor geplande gebeurtenissen opnieuw implementeren.
| Name |
Type |
Description |
|
automaticallyApprove
|
boolean
|
Hiermee geeft u configuraties voor geplande gebeurtenissen opnieuw implementeren.
|
VaultCertificate
Object
Beschrijft één certificaatverwijzing in een Sleutelkluis en waar het certificaat zich op de virtuele machine moet bevinden.
| Name |
Type |
Description |
|
certificateStore
|
string
|
Voor Virtuele Windows-machines geeft u het certificaatarchief op de virtuele machine waaraan het certificaat moet worden toegevoegd. Het opgegeven certificaatarchief bevindt zich impliciet in het LocalMachine-account. Voor Linux-VM's wordt het certificaatbestand onder de map /var/lib/waagent geplaatst, met de bestandsnaam <HoofdletterThumbprint>.crt voor het X509-certificaatbestand en <HoofdlettercaseThumbprint>.prv voor persoonlijke sleutel. Beide bestanden zijn .pem-indeling.
|
|
certificateUrl
|
string
|
Dit is de URL van een certificaat dat als geheim is geüpload naar Key Vault. Zie Een sleutel of geheim toevoegen aan de sleutelkluisvoor informatie over het toevoegen van een geheim aan de sleutelkluis. In dit geval moet uw certificaat de Base64-codering zijn van het volgende JSON-object dat is gecodeerd in UTF-8:
{ "data":"<Base64-gecodeerd-certificaat>", "dataType":"pfx", "password":"<pfx-file-password>" } Als u certificaten op een virtuele machine wilt installeren, wordt u aangeraden de extensie van de virtuele Azure Key Vault-machine voor Linux- of de virtuele Machine-extensie van Azure Key Vault voor Windowste gebruiken.
|
VaultSecretGroup
Object
Beschrijft een set certificaten die zich allemaal in dezelfde Key Vault bevinden.
| Name |
Type |
Description |
|
sourceVault
|
SubResource
|
De relatieve URL van de Sleutelkluis met alle certificaten in VaultCertificates.
|
|
vaultCertificates
|
VaultCertificate[]
|
De lijst met sleutelkluisverwijzingen in SourceVault die certificaten bevatten.
|
VirtualHardDisk
Object
Beschrijft de URI van een schijf.
| Name |
Type |
Description |
|
uri
|
string
|
Hiermee geeft u de URI van de virtuele harde schijf.
|
VirtualMachine
Object
Beschrijft een virtuele machine.
| Name |
Type |
Description |
|
etag
|
string
|
Etag is eigenschap die wordt geretourneerd in het antwoord maken/bijwerken/ophalen van de virtuele machine, zodat de klant deze kan opgeven in de header om optimistische updates te garanderen.
|
|
extendedLocation
|
ExtendedLocation
|
De uitgebreide locatie van de virtuele machine.
|
|
id
|
string
|
Volledig gekwalificeerde resource-id voor de resource. Bijv. - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}
|
|
identity
|
VirtualMachineIdentity
|
De identiteit van de virtuele machine, indien geconfigureerd.
|
|
location
|
string
|
De geografische locatie waar de resource zich bevindt
|
|
managedBy
|
string
|
ManagedBy is ingesteld op VIRTUAL Machine Scale Set (VMSS) flex ARM resourceID, als de VM deel uitmaakt van de VMSS. Deze eigenschap wordt gebruikt door het platform voor het verwijderen van interne resourcegroepen.
|
|
name
|
string
|
De naam van de resource
|
|
placement
|
Placement
|
In de sectie Plaatsing worden de door de gebruiker gedefinieerde beperkingen opgegeven voor de plaatsing van hardware van virtuele machines. Deze eigenschap kan niet worden gewijzigd zodra de VM is ingericht. Minimale API-versie: 2024-11-01.
|
|
plan
|
Plan
|
Hiermee geeft u informatie op over de marketplace-installatiekopieën die worden gebruikt om de virtuele machine te maken. Dit element wordt alleen gebruikt voor Marketplace-installatiekopieën. Voordat u een Marketplace-installatiekopieën van een API kunt gebruiken, moet u de installatiekopieën inschakelen voor programmatisch gebruik. Zoek in Azure Portal de marketplace-installatiekopieën die u wilt gebruiken en klik vervolgens op Programmatisch wilt implementeren, Aan de slag ->. Voer de vereiste gegevens in en klik vervolgens op Opslaan.
|
|
properties.additionalCapabilities
|
AdditionalCapabilities
|
Hiermee geeft u aanvullende mogelijkheden op die zijn ingeschakeld of uitgeschakeld op de virtuele machine.
|
|
properties.applicationProfile
|
ApplicationProfile
|
Hiermee geeft u de galerietoepassingen op die beschikbaar moeten worden gesteld voor de VM/VMSS.
|
|
properties.availabilitySet
|
SubResource
|
Hiermee geeft u informatie op over de beschikbaarheidsset waaraan de virtuele machine moet worden toegewezen. Virtuele machines die zijn opgegeven in dezelfde beschikbaarheidsset, worden toegewezen aan verschillende knooppunten om de beschikbaarheid te maximaliseren. Zie Overzicht van beschikbaarheidssetsvoor meer informatie over beschikbaarheidssets. Zie Onderhoud en updates voor virtuele machines in Azurevoor meer informatie over gepland azure-onderhoud. Op dit moment kan een VIRTUELE machine alleen worden toegevoegd aan de beschikbaarheidsset tijdens het maken. De beschikbaarheidsset waaraan de VIRTUELE machine wordt toegevoegd, moet zich onder dezelfde resourcegroep bevinden als de resource van de beschikbaarheidsset. Een bestaande VM kan niet worden toegevoegd aan een beschikbaarheidsset. Deze eigenschap kan niet samen met een verwijzing naar niet-null properties.virtualMachineScaleSet bestaan.
|
|
properties.billingProfile
|
BillingProfile
|
Hiermee geeft u de factureringsgerelateerde details van een virtuele Azure Spot-machine op. Minimale API-versie: 2019-03-01.
|
|
properties.capacityReservation
|
CapacityReservationProfile
|
Hiermee geeft u informatie op over de capaciteitsreservering die wordt gebruikt om virtuele machine toe te wijzen. Minimale API-versie: 2021-04-01.
|
|
properties.diagnosticsProfile
|
DiagnosticsProfile
|
Hiermee geeft u de status van diagnostische instellingen voor opstarten. Minimale API-versie: 2015-06-15.
|
|
properties.evictionPolicy
|
VirtualMachineEvictionPolicyTypes
|
Hiermee geeft u het verwijderingsbeleid voor de virtuele Azure Spot-machine en Azure Spot-schaalset op. Voor virtuele Azure Spot-machines worden zowel Toewijzing ongedaan maken als Verwijderen ondersteund en is de minimale API-versie 2019-03-01. Voor Azure Spot-schaalsets worden zowel 'Toewijzing ongedaan maken' als 'Verwijderen' ondersteund en is de minimale API-versie 2017-10-30-preview.
|
|
properties.extensionsTimeBudget
|
string
|
Hiermee geeft u de tijd die is toegewezen voor alle extensies die moeten worden gestart. De tijdsduur moet liggen tussen 15 minuten en 120 minuten (inclusief) en moet worden opgegeven in ISO 8601-indeling. De standaardwaarde is 90 minuten (PT1H30M). Minimale API-versie: 2020-06-01.
|
|
properties.hardwareProfile
|
HardwareProfile
|
Hiermee geeft u de hardware-instellingen voor de virtuele machine.
|
|
properties.host
|
SubResource
|
Hiermee geeft u informatie op over de toegewezen host waarin de virtuele machine zich bevindt. Minimale API-versie: 2018-10-01.
|
|
properties.hostGroup
|
SubResource
|
Hiermee geeft u informatie op over de toegewezen hostgroep waarin de virtuele machine zich bevindt.
Opmerking: gebruiker kan de eigenschappen host en hostGroup niet opgeven. Minimale API-versie: 2020-06-01.
|
|
properties.instanceView
|
VirtualMachineInstanceView
|
De weergave van het exemplaar van de virtuele machine.
|
|
properties.interconnectBlockProfile
|
InterconnectBlockProfile
|
Specificeert informatie over het Interconnect Block dat wordt gebruikt om de Virtual Machine toe te wijzen. Minimale api-versie: 2026-03-01.
|
|
properties.licenseType
|
string
|
Hiermee geeft u op dat de installatiekopieën of schijven die worden gebruikt, on-premises zijn gelicentieerd.
Mogelijke waarden voor het Windows Server-besturingssysteem zijn:
Windows_Client
Windows_Server
Mogelijke waarden voor het Linux Server-besturingssysteem zijn:
RHEL_BYOS (voor RHEL)
SLES_BYOS (voor SUSE)
Zie Azure Hybrid Use Benefit voor Windows Server voor meer informatie
Azure Hybrid Use Benefit voor Linux Server-
Minimale API-versie: 2015-06-15
|
|
properties.networkProfile
|
NetworkProfile
|
Hiermee geeft u de netwerkinterfaces van de virtuele machine.
|
|
properties.osProfile
|
OSProfile
|
Hiermee geeft u de instellingen van het besturingssysteem op die worden gebruikt tijdens het maken van de virtuele machine. Sommige instellingen kunnen niet worden gewijzigd zodra de VIRTUELE machine is ingericht.
|
|
properties.platformFaultDomain
|
integer
(int32)
|
Hiermee geeft u het logische foutdomein van de schaalset waarin de virtuele machine wordt gemaakt. De virtuele machine wordt standaard automatisch toegewezen aan een foutdomein dat de beste balans behoudt tussen beschikbare foutdomeinen. Dit is alleen van toepassing als de eigenschap virtualMachineScaleSet van deze virtuele machine is ingesteld. De virtuele-machineschaalset waarnaar wordt verwezen, moet 'platformFaultDomainCount' groter dan 1 hebben. Deze eigenschap kan niet worden bijgewerkt zodra de virtuele machine is gemaakt. Foutdomeintoewijzing kan worden weergegeven in de weergave exemplaar van de virtuele machine. Minimale API-versie: 2020-12-01.
|
|
properties.priority
|
VirtualMachinePriorityTypes
|
Hiermee geeft u de prioriteit voor de virtuele machine. Minimale API-versie: 2019-03-01
|
|
properties.provisioningState
|
string
|
De inrichtingsstatus, die alleen in het antwoord wordt weergegeven.
|
|
properties.proximityPlacementGroup
|
SubResource
|
Hiermee geeft u informatie op over de nabijheidsplaatsingsgroep waaraan de virtuele machine moet worden toegewezen. Minimale API-versie: 2018-04-01.
|
|
properties.resiliencyProfile
|
ResiliencyProfile
|
Veerkrachtprofiel voor de virtuele machine.
|
|
properties.scheduledEventsPolicy
|
ScheduledEventsPolicy
|
Hiermee geeft u configuraties met betrekking tot geplande gebeurtenissen opnieuw implementeren, opnieuw opstarten en ScheduledEventsAdditionalPublishingTargets Scheduled Event voor de virtuele machine.
|
|
properties.scheduledEventsProfile
|
ScheduledEventsProfile
|
Hiermee geeft u configuraties met betrekking tot geplande gebeurtenissen op.
|
|
properties.securityProfile
|
SecurityProfile
|
Hiermee geeft u de beveiligingsgerelateerde profielinstellingen voor de virtuele machine.
|
|
properties.storageProfile
|
StorageProfile
|
Hiermee geeft u de opslaginstellingen voor de schijven van de virtuele machine op.
|
|
properties.timeCreated
|
string
(date-time)
|
Hiermee geeft u het tijdstip op waarop de virtuele-machineresource is gemaakt. Minimale API-versie: 2021-11-01.
|
|
properties.userData
|
string
|
UserData voor de VIRTUELE machine, die base-64 moet zijn gecodeerd. De klant mag hier geen geheimen doorgeven. Minimale API-versie: 2021-03-01.
|
|
properties.virtualMachineScaleSet
|
SubResource
|
Hiermee geeft u informatie op over de virtuele-machineschaalset waaraan de virtuele machine moet worden toegewezen. Virtuele machines die zijn opgegeven in dezelfde virtuele-machineschaalset, worden toegewezen aan verschillende knooppunten om de beschikbaarheid te maximaliseren. Op dit moment kan een VIRTUELE machine alleen worden toegevoegd aan een virtuele-machineschaalset tijdens het maken. Een bestaande VM kan niet worden toegevoegd aan een virtuele-machineschaalset. Deze eigenschap kan niet bestaan samen met een verwijzing naar niet-null properties.availabilitySet. Minimale API-versie: 2019-03-01.
|
|
properties.vmId
|
string
|
Hiermee geeft u de unieke VM-id op die een id van 128 bits is die is gecodeerd en opgeslagen in alle SMBIOS-vm's van Azure IaaS en kan worden gelezen met behulp van BIOS-opdrachten van het platform.
|
|
resources
|
VirtualMachineExtension[]
|
De onderliggende extensiebronnen van de virtuele machine.
|
|
systemData
|
systemData
|
Azure Resource Manager-metagegevens met createdBy- en modifiedBy-gegevens.
|
|
tags
|
object
|
Resourcetags.
|
|
type
|
string
|
Het type bron. Bijvoorbeeld 'Microsoft.Compute/virtualMachines' of 'Microsoft.Storage/storageAccounts'
|
|
zones
|
string[]
|
De beschikbaarheidszones.
|
VirtualMachineAgentInstanceView
Object
De exemplaarweergave van de VM-agent die wordt uitgevoerd op de virtuele machine.
VirtualMachineEvictionPolicyTypes
Opsomming
Hiermee geeft u het uitzettingsbeleid op voor de Azure Spot VM/VMSS
| Waarde |
Description |
|
Deallocate
|
|
|
Delete
|
|
VirtualMachineExtension
Object
Beschrijft een virtuele-machineextensie.
| Name |
Type |
Description |
|
id
|
string
|
Volledig gekwalificeerde resource-id voor de resource. Bijv. - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}
|
|
location
|
string
|
De geografische locatie waar de resource zich bevindt
|
|
name
|
string
|
De naam van de resource
|
|
properties.autoUpgradeMinorVersion
|
boolean
|
Geeft aan of de extensie een nieuwere secundaire versie moet gebruiken als deze beschikbaar is tijdens de implementatie. Zodra de extensie eenmaal is geïmplementeerd, worden er echter geen secundaire versies bijgewerkt, tenzij deze opnieuw wordt geïmplementeerd, zelfs niet als deze eigenschap is ingesteld op true.
|
|
properties.enableAutomaticUpgrade
|
boolean
|
Geeft aan of de extensie automatisch moet worden bijgewerkt door het platform als er een nieuwere versie van de extensie beschikbaar is.
|
|
properties.forceUpdateTag
|
string
|
Hoe de extensie-handler moet worden gedwongen om bij te werken, zelfs als de extensieconfiguratie niet is gewijzigd.
|
|
properties.instanceView
|
VirtualMachineExtensionInstanceView
|
De weergave exemplaar van de virtuele-machine-extensie.
|
|
properties.protectedSettings
|
|
De extensie kan protectedSettings of protectedSettingsFromKeyVault of helemaal geen beveiligde instellingen bevatten.
|
|
properties.protectedSettingsFromKeyVault
|
KeyVaultSecretReference
|
De met extensies beveiligde instellingen die doorverwijzing worden doorgegeven en die worden gebruikt vanuit de sleutelkluis
|
|
properties.provisionAfterExtensions
|
string[]
|
Verzameling extensienamen waarna deze extensie moet worden ingericht.
|
|
properties.provisioningState
|
string
|
De inrichtingsstatus, die alleen in het antwoord wordt weergegeven.
|
|
properties.publisher
|
string
|
De naam van de uitgever van de extensie-handler.
|
|
properties.settings
|
|
In Json opgemaakte openbare instellingen voor de extensie.
|
|
properties.suppressFailures
|
boolean
|
Geeft aan of fouten die voortvloeien uit de extensie worden onderdrukt (operationele fouten, zoals het niet verbinden met de VIRTUELE machine, worden niet onderdrukt, ongeacht deze waarde). De standaardwaarde is onwaar.
|
|
properties.type
|
string
|
Hiermee geeft u het type van de extensie; een voorbeeld is CustomScriptExtension.
|
|
properties.typeHandlerVersion
|
string
|
Specificeert de Major.Minor-versie van de scripthandler. De klant kan alleen de Major.Minor-versie van een extensie specificeren, het Azure-platform levert de nieuwste Patch.Hotfix-versie in de Major.Minor-serie.
|
|
systemData
|
systemData
|
Azure Resource Manager-metagegevens met createdBy- en modifiedBy-gegevens.
|
|
tags
|
object
|
Resourcetags.
|
|
type
|
string
|
Het type bron. Bijvoorbeeld 'Microsoft.Compute/virtualMachines' of 'Microsoft.Storage/storageAccounts'
|
VirtualMachineExtensionHandlerInstanceView
Object
De exemplaarweergave van een handler voor de extensie van een virtuele machine.
| Name |
Type |
Description |
|
status
|
InstanceViewStatus
|
De status van de extensie-handler.
|
|
type
|
string
|
Hiermee geeft u het type van de extensie; een voorbeeld is CustomScriptExtension.
|
|
typeHandlerVersion
|
string
|
Specificeert de Major.Minor.Patch.Hotfix-versie van de scripthandler. Het Azure-platform zal de nieuwste Patch.Hotfix-versie leveren in de Major.Minor-serie.
|
VirtualMachineExtensionInstanceView
Object
De exemplaarweergave van een virtuele-machineextensie.
| Name |
Type |
Description |
|
name
|
string
|
De naam van de extensie van de virtuele machine.
|
|
statuses
|
InstanceViewStatus[]
|
De informatie over de resourcestatus.
|
|
substatuses
|
InstanceViewStatus[]
|
De informatie over de resourcestatus.
|
|
type
|
string
|
Hiermee geeft u het type van de extensie; een voorbeeld is CustomScriptExtension.
|
|
typeHandlerVersion
|
string
|
Specificeert de Major.Minor.Patch.Hotfix-versie van de scripthandler. Het Azure-platform zal de nieuwste Patch.Hotfix-versie leveren in de Major.Minor-serie.
|
VirtualMachineHealthStatus
Object
De status van de virtuele machine.
| Name |
Type |
Description |
|
status
|
InstanceViewStatus
|
De statusinformatie voor de VIRTUELE machine.
|
VirtualMachineIdentity
Object
Identiteit voor de virtuele machine.
| Name |
Type |
Description |
|
principalId
|
string
|
De principal-id van de identiteit van de virtuele machine. Deze eigenschap wordt alleen verstrekt voor een door het systeem toegewezen identiteit.
|
|
tenantId
|
string
|
De tenant-id die is gekoppeld aan de virtuele machine. Deze eigenschap wordt alleen verstrekt voor een door het systeem toegewezen identiteit.
|
|
type
|
ResourceIdentityType
|
Het type identiteit dat wordt gebruikt voor de virtuele machine. Het type SystemAssigned, UserAssigned bevat zowel een impliciet gemaakte identiteit als een set door de gebruiker toegewezen identiteiten. Met het type None worden alle identiteiten van de virtuele machine verwijderd.
|
|
userAssignedIdentities
|
<string,
Common.UserAssignedIdentitiesValue>
|
De lijst met gebruikersidentiteiten die zijn gekoppeld aan de virtuele machine. De sleutelverwijzingen voor de gebruikersidentiteitswoordenlijst zijn ARM-resource-id's in de vorm: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}.
|
VirtualMachineInstanceView
Object
De exemplaarweergave van een virtuele machine.
| Name |
Type |
Description |
|
assignedHost
|
string
|
Resource-id van de toegewezen host, waarop de virtuele machine wordt toegewezen via automatische plaatsing, wanneer de virtuele machine is gekoppeld aan een toegewezen hostgroep waarvoor automatische plaatsing is ingeschakeld. Minimale API-versie: 2020-06-01.
|
|
bootDiagnostics
|
BootDiagnosticsInstanceView
|
Diagnostische gegevens over opstarten is een functie voor foutopsporing waarmee u console-uitvoer en schermopname kunt bekijken om de VM-status te diagnosticeren. U kunt eenvoudig de uitvoer van uw consolelogboek bekijken. Met Azure kunt u ook een schermopname van de virtuele machine bekijken vanuit de hypervisor.
|
|
capacityReservationType
|
CapacityReservationType
|
Specificeert van welk type capaciteitsreservering de virtuele machine capaciteit zal verbruiken als deze in aanmerking komt, of dat deze expliciet is afgestemd op het gekoppeld zijn en verbruiken van capaciteit uit elke gereserveerde capaciteit die beschikbaar is in het abonnement. Minimale api-versie: 2026-04-01.
|
|
computerName
|
string
|
De computernaam die is toegewezen aan de virtuele machine.
|
|
disks
|
DiskInstanceView[]
|
De schijfgegevens van de virtuele machine.
|
|
extensions
|
VirtualMachineExtensionInstanceView[]
|
De uitbreidingsgegevens.
|
|
hyperVGeneration
|
HyperVGenerationType
|
Hiermee geeft u het HyperVGeneration-type dat is gekoppeld aan een resource
|
|
interconnectInstanceView
|
InterconnectInstanceView
|
De Interconnect-runtimeweergave van de Virtual Machine. Minimale api-versie: 2026-03-01.
|
|
isVMInStandbyPool
|
boolean
|
[Preview-functie] Hiermee geeft u op of de VIRTUELE machine zich momenteel in of buiten de stand-bypool bevindt.
|
|
maintenanceRedeployStatus
|
MaintenanceRedeployStatus
|
De onderhoudsbewerkingsstatus op de virtuele machine.
|
|
osName
|
string
|
Het besturingssysteem dat wordt uitgevoerd op de virtuele machine.
|
|
osVersion
|
string
|
De versie van het besturingssysteem die wordt uitgevoerd op de virtuele machine.
|
|
patchStatus
|
VirtualMachinePatchStatus
|
[Preview-functie] De status van patchbewerkingen voor virtuele machines.
|
|
platformFaultDomain
|
integer
(int32)
|
Hiermee geeft u het foutdomein van de virtuele machine.
|
|
platformUpdateDomain
|
integer
(int32)
|
Hiermee geeft u het updatedomein van de virtuele machine.
|
|
rdpThumbPrint
|
string
|
De vingerafdruk van het extern bureaublad-certificaat.
|
|
statuses
|
InstanceViewStatus[]
|
De informatie over de resourcestatus.
|
|
vmAgent
|
VirtualMachineAgentInstanceView
|
De VM-agent die wordt uitgevoerd op de virtuele machine.
|
|
vmHealth
|
VirtualMachineHealthStatus
|
De status van de VIRTUELE machine.
|
VirtualMachineIpTag
Object
Bevat de IP-tag die is gekoppeld aan het openbare IP-adres.
| Name |
Type |
Description |
|
firstPartyServiceTagId
|
string
(arm-id)
|
De resource-identificatie van de eerste partij servicetag gekoppeld aan het publieke IP-adres.
|
|
ipTagType
|
string
|
IP-tagtype. Voorbeeld: FirstPartyUsage.
|
|
tag
|
string
|
IP-tag die is gekoppeld aan het openbare IP-adres. Voorbeeld: SQL, Storage, enzovoort.
|
VirtualMachineNetworkInterfaceConfiguration
Object
Beschrijft een netwerkinterfaceconfiguratie voor virtuele machines.
| Name |
Type |
Description |
|
name
|
string
|
De naam van de netwerkinterfaceconfiguratie.
|
|
properties.auxiliaryMode
|
NetworkInterfaceAuxiliaryMode
|
Hiermee geeft u op of de hulpmodus is ingeschakeld voor de netwerkinterfaceresource.
|
|
properties.auxiliarySku
|
NetworkInterfaceAuxiliarySku
|
Hiermee geeft u op of de hulp-sku is ingeschakeld voor de netwerkinterfaceresource.
|
|
properties.deleteOption
|
DeleteOptions
|
Opgeven wat er gebeurt met de netwerkinterface wanneer de VIRTUELE machine wordt verwijderd
|
|
properties.disableTcpStateTracking
|
boolean
|
Hiermee geeft u op of de netwerkinterface is uitgeschakeld voor tcp-statustracering.
|
|
properties.dnsSettings
|
VirtualMachineNetworkInterfaceDnsSettingsConfiguration
|
De DNS-instellingen die moeten worden toegepast op de netwerkinterfaces.
|
|
properties.dscpConfiguration
|
SubResource
|
|
|
properties.enableAcceleratedNetworking
|
boolean
|
Hiermee geeft u op of de netwerkinterface versneld netwerken is ingeschakeld.
|
|
properties.enableFpga
|
boolean
|
Hiermee geeft u op of de netwerkinterface is ingeschakeld voor FPGA-netwerken.
|
|
properties.enableIPForwarding
|
boolean
|
Of doorsturen via IP is ingeschakeld op deze NIC.
|
|
properties.ipConfigurations
|
VirtualMachineNetworkInterfaceIPConfiguration[]
|
Hiermee geeft u de IP-configuraties van de netwerkinterface.
|
|
properties.networkSecurityGroup
|
SubResource
|
De netwerkbeveiligingsgroep.
|
|
properties.primary
|
boolean
|
Hiermee geeft u de primaire netwerkinterface op voor het geval de virtuele machine meer dan 1 netwerkinterface heeft.
|
|
tags
|
object
|
Brontags die worden toegepast op het networkInterface-adres dat door deze NetworkInterfaceConfiguration is gemaakt
|
VirtualMachineNetworkInterfaceDnsSettingsConfiguration
Object
Beschrijft de DNS-instellingen van de netwerkconfiguratie van een virtuele machine.
| Name |
Type |
Description |
|
dnsServers
|
string[]
|
Lijst met IP-adressen van DNS-servers
|
VirtualMachineNetworkInterfaceIPConfiguration
Object
Beschrijft de IP-configuratie van een netwerkprofiel voor een virtuele machine.
| Name |
Type |
Description |
|
name
|
string
|
De naam van de IP-configuratie.
|
|
properties.applicationGatewayBackendAddressPools
|
SubResource[]
|
Hiermee geeft u een matrix van verwijzingen naar back-endadresgroepen van toepassingsgateways. Een virtuele machine kan verwijzen naar back-endadresgroepen van meerdere toepassingsgateways. Meerdere virtuele machines kunnen niet dezelfde toepassingsgateway gebruiken.
|
|
properties.applicationSecurityGroups
|
SubResource[]
|
Hiermee geeft u een matrix van verwijzingen naar toepassingsbeveiligingsgroep.
|
|
properties.loadBalancerBackendAddressPools
|
SubResource[]
|
Hiermee geeft u een matrix van verwijzingen naar back-endadresgroepen van load balancers. Een virtuele machine kan verwijzen naar back-endadresgroepen van één openbare en één interne load balancer. [Meerdere virtuele machines kunnen niet dezelfde basic sku load balancer gebruiken].
|
|
properties.primary
|
boolean
|
Hiermee geeft u de primaire netwerkinterface op voor het geval de virtuele machine meer dan 1 netwerkinterface heeft.
|
|
properties.privateIPAddressVersion
|
IPVersions
|
Vanaf Api-Version 2017-03-30 wordt aangegeven of de specifieke ipconfiguratie IPv4 of IPv6 is. De standaardwaarde wordt gebruikt als IPv4. Mogelijke waarden zijn: 'IPv4' en 'IPv6'.
|
|
properties.publicIPAddressConfiguration
|
VirtualMachinePublicIPAddressConfiguration
|
De publicIPAddressConfiguration.
|
|
properties.subnet
|
SubResource
|
Hiermee geeft u de id van het subnet.
|
VirtualMachinePatchStatus
Object
De status van patchbewerkingen voor virtuele machines.
| Name |
Type |
Description |
|
availablePatchSummary
|
AvailablePatchSummary
|
Het beschikbare patchoverzicht van de meest recente evaluatiebewerking voor de virtuele machine.
|
|
configurationStatuses
|
InstanceViewStatus[]
|
De activeringsstatus van de opgegeven patchMode
|
|
lastPatchInstallationSummary
|
LastPatchInstallationSummary
|
Het installatieoverzicht van de meest recente installatiebewerking voor de virtuele machine.
|
VirtualMachinePriorityTypes
Opsomming
Hiermee geeft u de prioriteit op voor een zelfstandige virtuele machine of de virtuele machines in de schaalset.
| Waarde |
Description |
|
Regular
|
Reguliere prioriteit voor een zelfstandige virtuele machine of de virtuele machines in de schaalset.
Dit is de standaardprioriteit en wordt gebruikt om reguliere VM/VMSS uit te rollen.
|
|
Low
|
Lage prioriteit voor een zelfstandige virtuele machine of de virtuele machines in de schaalset. Wordt dan afgekeurd, gebruik dan Spot.
|
|
Spot
|
Spotprioriteit voor een standalone virtuele machine of de virtuele machines in de schaalset.
|
|
SpotPlus
|
SpotPlus-prioriteit voor een zelfstandige virtuele machine of de virtuele machines in de schaalset.
Dit is een enumwaarde die zal worden gebruikt om Azure Spot Plus VM/VMSS te implementeren, de volgende generatie Azure Spot VM/VMSS met meer betrouwbaarheid en langere looptijd.
|
VirtualMachinePublicIPAddressConfiguration
Object
Beschrijft de publicIPAddress-configuratie van een virtuele machine
| Name |
Type |
Description |
|
name
|
string
|
De configuratienaam van het publicIP-adres.
|
|
properties.deleteOption
|
DeleteOptions
|
Opgeven wat er gebeurt met het openbare IP-adres wanneer de virtuele machine wordt verwijderd
|
|
properties.dnsSettings
|
VirtualMachinePublicIPAddressDnsSettingsConfiguration
|
De DNS-instellingen die moeten worden toegepast op de publicIP-adressen.
|
|
properties.idleTimeoutInMinutes
|
integer
(int32)
|
De time-out voor inactiviteit van het openbare IP-adres.
|
|
properties.ipTags
|
VirtualMachineIpTag[]
|
De lijst met IP-tags die zijn gekoppeld aan het openbare IP-adres.
|
|
properties.publicIPAddressVersion
|
IPVersions
|
Vanaf Api-Version 2019-07-01 wordt aangegeven of de specifieke ipconfiguratie IPv4 of IPv6 is. De standaardwaarde wordt gebruikt als IPv4. Mogelijke waarden zijn: 'IPv4' en 'IPv6'.
|
|
properties.publicIPAllocationMethod
|
PublicIPAllocationMethod
|
Geef het type openbare IP-toewijzing op
|
|
properties.publicIPPrefix
|
SubResource
|
Het PublicIPPrefix waaruit openbareIP-adressen moeten worden toegewezen.
|
|
sku
|
PublicIPAddressSku
|
Beschrijft de openbare IP-SKU. Deze kan alleen worden ingesteld met OrchestrationMode als Flexible.
|
|
tags
|
object
|
Resource-tags die worden toegepast op het publicIP-adres dat door deze PublicIPAddressConfiguration is gemaakt
|
VirtualMachinePublicIPAddressDnsSettingsConfiguration
Object
Beschrijft de DNS-instellingen van de netwerkconfiguratie van een virtuele machine.
| Name |
Type |
Description |
|
domainNameLabel
|
string
|
Het labelvoorvoegsel van de PublicIPAddress-resources die worden gemaakt. Het gegenereerde naamlabel is de samenvoeging van het domeinnaamlabel en de unieke id van het vm-netwerkprofiel.
|
|
domainNameLabelScope
|
DomainNameLabelScopeTypes
|
Het labelbereik domeinnaam van de PublicIPAddress-resources die worden gemaakt. Het gegenereerde naamlabel is de samenvoeging van het gehashte domeinnaamlabel met beleid volgens het labelbereik van de domeinnaam en de unieke id van het VM-netwerkprofiel.
|
VirtualMachineSizeTypes
Opsomming
Hiermee geeft u de grootte van de virtuele machine. Het enum-gegevenstype is momenteel afgeschaft en wordt op 23 december 2023 verwijderd. De aanbevolen manier om de lijst met beschikbare grootten op te halen, is met behulp van deze API's: Alle beschikbare grootten van virtuele machines in een beschikbaarheidsset weergeven, Alle beschikbare grootten van virtuele machines in een regio weergeven, Alle beschikbare grootten van virtuele machines weergeven voor het wijzigen van de grootte van. Zie Grootten voor virtuele machinesvoor meer informatie over de grootte van virtuele machines. De beschikbare VM-grootten zijn afhankelijk van de regio en beschikbaarheidsset.
| Waarde |
Description |
|
Basic_A0
|
|
|
Basic_A1
|
|
|
Basic_A2
|
|
|
Basic_A3
|
|
|
Basic_A4
|
|
|
Standard_A0
|
|
|
Standard_A1
|
|
|
Standard_A2
|
|
|
Standard_A3
|
|
|
Standard_A4
|
|
|
Standard_A5
|
|
|
Standard_A6
|
|
|
Standard_A7
|
|
|
Standard_A8
|
|
|
Standard_A9
|
|
|
Standard_A10
|
|
|
Standard_A11
|
|
|
Standard_A1_v2
|
|
|
Standard_A2_v2
|
|
|
Standard_A4_v2
|
|
|
Standard_A8_v2
|
|
|
Standard_A2m_v2
|
|
|
Standard_A4m_v2
|
|
|
Standard_A8m_v2
|
|
|
Standard_B1s
|
|
|
Standard_B1ms
|
|
|
Standard_B2s
|
|
|
Standard_B2ms
|
|
|
Standard_B4ms
|
|
|
Standard_B8ms
|
|
|
Standard_D1
|
|
|
Standard_D2
|
|
|
Standard_D3
|
|
|
Standard_D4
|
|
|
Standard_D11
|
|
|
Standard_D12
|
|
|
Standard_D13
|
|
|
Standard_D14
|
|
|
Standard_D1_v2
|
|
|
Standard_D2_v2
|
|
|
Standard_D3_v2
|
|
|
Standard_D4_v2
|
|
|
Standard_D5_v2
|
|
|
Standard_D2_v3
|
|
|
Standard_D4_v3
|
|
|
Standard_D8_v3
|
|
|
Standard_D16_v3
|
|
|
Standard_D32_v3
|
|
|
Standard_D64_v3
|
|
|
Standard_D2s_v3
|
|
|
Standard_D4s_v3
|
|
|
Standard_D8s_v3
|
|
|
Standard_D16s_v3
|
|
|
Standard_D32s_v3
|
|
|
Standard_D64s_v3
|
|
|
Standard_D11_v2
|
|
|
Standard_D12_v2
|
|
|
Standard_D13_v2
|
|
|
Standard_D14_v2
|
|
|
Standard_D15_v2
|
|
|
Standard_DS1
|
|
|
Standard_DS2
|
|
|
Standard_DS3
|
|
|
Standard_DS4
|
|
|
Standard_DS11
|
|
|
Standard_DS12
|
|
|
Standard_DS13
|
|
|
Standard_DS14
|
|
|
Standard_DS1_v2
|
|
|
Standard_DS2_v2
|
|
|
Standard_DS3_v2
|
|
|
Standard_DS4_v2
|
|
|
Standard_DS5_v2
|
|
|
Standard_DS11_v2
|
|
|
Standard_DS12_v2
|
|
|
Standard_DS13_v2
|
|
|
Standard_DS14_v2
|
|
|
Standard_DS15_v2
|
|
|
Standard_DS13-4_v2
|
|
|
Standard_DS13-2_v2
|
|
|
Standard_DS14-8_v2
|
|
|
Standard_DS14-4_v2
|
|
|
Standard_E2_v3
|
|
|
Standard_E4_v3
|
|
|
Standard_E8_v3
|
|
|
Standard_E16_v3
|
|
|
Standard_E32_v3
|
|
|
Standard_E64_v3
|
|
|
Standard_E2s_v3
|
|
|
Standard_E4s_v3
|
|
|
Standard_E8s_v3
|
|
|
Standard_E16s_v3
|
|
|
Standard_E32s_v3
|
|
|
Standard_E64s_v3
|
|
|
Standard_E32-16_v3
|
|
|
Standard_E32-8s_v3
|
|
|
Standard_E64-32s_v3
|
|
|
Standard_E64-16s_v3
|
|
|
Standard_F1
|
|
|
Standard_F2
|
|
|
Standard_F4
|
|
|
Standard_F8
|
|
|
Standard_F16
|
|
|
Standard_F1s
|
|
|
Standard_F2s
|
|
|
Standard_F4s
|
|
|
Standard_F8s
|
|
|
Standard_F16s
|
|
|
Standard_F2s_v2
|
|
|
Standard_F4s_v2
|
|
|
Standard_F8s_v2
|
|
|
Standard_F16s_v2
|
|
|
Standard_F32s_v2
|
|
|
Standard_F64s_v2
|
|
|
Standard_F72s_v2
|
|
|
Standard_G1
|
|
|
Standard_G2
|
|
|
Standard_G3
|
|
|
Standard_G4
|
|
|
Standard_G5
|
|
|
Standard_GS1
|
|
|
Standard_GS2
|
|
|
Standard_GS3
|
|
|
Standard_GS4
|
|
|
Standard_GS5
|
|
|
Standard_GS4-8
|
|
|
Standard_GS4-4
|
|
|
Standard_GS5-16
|
|
|
Standard_GS5-8
|
|
|
Standard_H8
|
|
|
Standard_H16
|
|
|
Standard_H8m
|
|
|
Standard_H16m
|
|
|
Standard_H16r
|
|
|
Standard_H16mr
|
|
|
Standard_L4s
|
|
|
Standard_L8s
|
|
|
Standard_L16s
|
|
|
Standard_L32s
|
|
|
Standard_M64s
|
|
|
Standard_M64ms
|
|
|
Standard_M128s
|
|
|
Standard_M128ms
|
|
|
Standard_M64-32ms
|
|
|
Standard_M64-16ms
|
|
|
Standard_M128-64ms
|
|
|
Standard_M128-32ms
|
|
|
Standard_NC6
|
|
|
Standard_NC12
|
|
|
Standard_NC24
|
|
|
Standard_NC24r
|
|
|
Standard_NC6s_v2
|
|
|
Standard_NC12s_v2
|
|
|
Standard_NC24s_v2
|
|
|
Standard_NC24rs_v2
|
|
|
Standard_NC6s_v3
|
|
|
Standard_NC12s_v3
|
|
|
Standard_NC24s_v3
|
|
|
Standard_NC24rs_v3
|
|
|
Standard_ND6s
|
|
|
Standard_ND12s
|
|
|
Standard_ND24s
|
|
|
Standard_ND24rs
|
|
|
Standard_NV6
|
|
|
Standard_NV12
|
|
|
Standard_NV24
|
|
VMDiskSecurityProfile
Object
Hiermee geeft u de beveiligingsprofielinstellingen voor de beheerde schijf.
Opmerking: Deze kan alleen worden ingesteld voor vertrouwelijke VM's.
| Name |
Type |
Description |
|
diskEncryptionSet
|
DiskEncryptionSetParameters
|
Hiermee geeft u de door de klant beheerde schijfversleutelingssetresource-id op voor de beheerde schijf die wordt gebruikt voor door de klant beheerde sleutel versleutelde ConfidentialVM-besturingssysteemschijf en VMGuest-blob.
|
|
securityEncryptionType
|
SecurityEncryptionTypes
|
Hiermee geeft u het EncryptionType van de beheerde schijf. Deze is ingesteld op DiskWithVMGuestState voor versleuteling van de beheerde schijf, samen met VMGuestState-blob, VMGuestStateOnly voor versleuteling van alleen de VMGuestState-blob en NonPersistedTPM voor het niet behouden van de firmwarestatus in de VMGuestState-blob..
Opmerking: Deze kan alleen worden ingesteld voor vertrouwelijke VM's.
|
VMGalleryApplication
Object
Hiermee geeft u de vereiste informatie om te verwijzen naar een toepassingsversie van een rekengalerie
| Name |
Type |
Description |
|
configurationReference
|
string
|
Optioneel: hiermee geeft u de URI op naar een Azure-blob die de standaardconfiguratie voor het pakket vervangt, indien opgegeven
|
|
enableAutomaticUpgrade
|
boolean
|
Als deze optie is ingesteld op true, wordt deze automatisch bijgewerkt voor de VM/VMSS wanneer een nieuwe versie van de galerietoepassing beschikbaar is in PIR/SIG
|
|
order
|
integer
(int32)
|
Optioneel: hiermee geeft u de volgorde op waarin de pakketten moeten worden geïnstalleerd
|
|
packageReferenceId
|
string
|
Hiermee geeft u de resource-id GalleryApplicationVersion op in de vorm van /subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/Microsoft.Compute/galleries/{galleryName}/applications/{application}/versions/{version}
|
|
tags
|
string
|
Optioneel, geeft een passthrough-waarde voor meer algemene context.
|
|
treatFailureAsDeploymentFailure
|
boolean
|
Optioneel, indien waar, een fout voor een bewerking in de VmApplication mislukt de implementatie
|
VMSizeProperties
Object
Hiermee geeft u de instellingen voor de eigenschap VM-grootte op de virtuele machine.
| Name |
Type |
Description |
|
vCPUsAvailable
|
integer
(int32)
|
Hiermee geeft u het aantal vCPU's dat beschikbaar is voor de virtuele machine. Wanneer deze eigenschap niet is opgegeven in de aanvraagbody, wordt het standaardgedrag ingesteld op de waarde van vCPU's die beschikbaar zijn voor die VM-grootte die beschikbaar is in api-antwoord van Alle beschikbare grootten van virtuele machines in een regio weergeven.
|
|
vCPUsPerCore
|
integer
(int32)
|
Hiermee geeft u de verhouding tussen vCPU en fysieke kern. Wanneer deze eigenschap niet is opgegeven in de aanvraagbody, wordt het standaardgedrag ingesteld op de waarde van vCPUUsPerCore voor de VM-grootte die wordt weergegeven in api-antwoord van Alle beschikbare grootten van virtuele machines in een regio weergeven.
Deze eigenschap instellen op 1 betekent ook dat hyperthreading is uitgeschakeld.
|
WindowsConfiguration
Object
Hiermee geeft u windows-besturingssysteeminstellingen op de virtuele machine.
| Name |
Type |
Description |
|
additionalUnattendContent
|
AdditionalUnattendContent[]
|
Hiermee geeft u aanvullende base-64 gecodeerde XML-geformatteerde informatie op die kan worden opgenomen in het Unattend.xml-bestand, dat wordt gebruikt door Windows Setup.
|
|
enableAutomaticUpdates
|
boolean
|
Hiermee wordt aangegeven of Automatische updates is ingeschakeld voor de virtuele Windows-machine. De standaardwaarde is waar. Voor virtuele-machineschaalsets kan deze eigenschap worden bijgewerkt en worden updates van kracht bij het opnieuw inrichten van het besturingssysteem.
|
|
enableVMAgentPlatformUpdates
|
boolean
|
Geeft aan of VMAgent-platformupdates zijn ingeschakeld voor de virtuele Windows-machine.
|
|
patchSettings
|
PatchSettings
|
[Preview-functie] Hiermee geeft u instellingen met betrekking tot VM-gastpatching in Windows.
|
|
provisionVMAgent
|
boolean
|
Hiermee wordt aangegeven of de virtuele-machineagent moet worden ingericht op de virtuele machine. Wanneer deze eigenschap niet is opgegeven in de hoofdtekst van de aanvraag, is deze standaard ingesteld op true. Dit zorgt ervoor dat de VM-agent op de VIRTUELE machine is geïnstalleerd, zodat extensies later aan de VIRTUELE machine kunnen worden toegevoegd.
|
|
timeZone
|
string
|
Hiermee geeft u de tijdzone van de virtuele machine. bijvoorbeeld "Pacific Standard Time". Mogelijke waarden kunnen worden TimeZoneInfo.Id waarde uit tijdzones die worden geretourneerd door TimeZoneInfo.GetSystemTimeZones.
|
|
winRM
|
WinRMConfiguration
|
Hiermee geeft u de listeners voor Extern beheer van Windows op. Hiermee schakelt u externe Windows PowerShell in.
|
WindowsPatchAssessmentMode
Opsomming
Hiermee geeft u de modus van vm-gastpatchevaluatie voor de virtuele IaaS-machine.
Mogelijke waarden zijn:
ImageDefault-: u bepaalt de timing van patchevaluaties op een virtuele machine.
AutomaticByPlatform - Het platform activeert periodieke patchevaluaties. De eigenschap provisionVMAgent moet waar zijn.
| Waarde |
Description |
|
ImageDefault
|
|
|
AutomaticByPlatform
|
|
Opsomming
Hiermee geeft u de instelling voor opnieuw opstarten voor alle installatiebewerkingen van de AutomaticByPlatform-patch.
| Waarde |
Description |
|
Unknown
|
|
|
IfRequired
|
|
|
Never
|
|
|
Always
|
|
Object
Hiermee geeft u aanvullende instellingen op die moeten worden toegepast wanneer de patchmodus AutomaticByPlatform is geselecteerd in de Windows-patchinstellingen.
| Name |
Type |
Description |
|
bypassPlatformSafetyChecksOnUserSchedule
|
boolean
|
Stelt de klant in staat patches te plannen zonder onbedoelde upgrades
|
|
rebootSetting
|
WindowsVMGuestPatchAutomaticByPlatformRebootSetting
|
Hiermee geeft u de instelling voor opnieuw opstarten voor alle installatiebewerkingen van de AutomaticByPlatform-patch.
|
WindowsVMGuestPatchMode
Opsomming
Hiermee geeft u de modus van VM-gastpatching naar virtuele IaaS-machine of virtuele machines die zijn gekoppeld aan virtuele-machineschaalset met OrchestrationMode als Flexibel.
Mogelijke waarden zijn:
Handmatig: u beheert de toepassing van patches op een virtuele machine. U doet dit door patches handmatig toe te passen in de VIRTUELE machine. In deze modus worden automatische updates uitgeschakeld; de eigenschap WindowsConfiguration.enableAutomaticUpdates moet onwaar zijn
AutomaticByOS : de virtuele machine wordt automatisch bijgewerkt door het besturingssysteem. De eigenschap WindowsConfiguration.enableAutomaticUpdates moet waar zijn.
AutomaticByPlatform : de virtuele machine wordt automatisch bijgewerkt door het platform. De eigenschappen provisionVMAgent en WindowsConfiguration.enableAutomaticUpdates moeten waar zijn
| Waarde |
Description |
|
Manual
|
|
|
AutomaticByOS
|
|
|
AutomaticByPlatform
|
|
WinRMConfiguration
Object
Hierin wordt de configuratie van Windows Remote Management van de VM beschreven
| Name |
Type |
Description |
|
listeners
|
WinRMListener[]
|
De lijst met Windows Remote Management-listeners
|
WinRMListener
Object
Beschrijft protocol en vingerafdruk van Windows Remote Management-listener
ZoneMovement
Object
Beschrijft de configuratie van zonebewegingen. Dit maakt het mogelijk om VM tijdens een storing tussen beschikbaarheidszones te verplaatsen.
| Name |
Type |
Description |
|
isEnabled
|
boolean
|
Geeft aan of zonebeweging is ingeschakeld. Standaard is isEnabled ingesteld op false, dat wil zeggen dat VM niet van de ene zone naar de andere kan worden verplaatst.
|
ZonePlacementPolicyType
Opsomming
Hiermee geeft u het beleid op voor de plaatsing van de resource in de beschikbaarheidszone. Mogelijke waarden zijn: Alle (gebruikt voor virtuele machines), Auto (gebruikt voor virtuele-machineschaalsets) - Een beschikbaarheidszone wordt automatisch door het systeem gekozen als onderdeel van het maken van resources.
| Waarde |
Description |
|
Any
|
|
|
Auto
|
Automatische zoneplaatsing in een schaalset van een virtuele machine.
|