The Update-AzVM cmdlet updates the state of an Azure virtual machine to the state of a virtual machine object.
Use PreferredVMSize in any parameter set to set the preview FlexProfile.PreferredVMSize.
Azure may deploy the preferred size or a compatible alternative based on capacity and placement.
This parameter overrides HardwareProfile.VmSize in the outgoing request without mutating the input object's HardwareProfile or FlexProfile.
When omitted, the input object's FlexProfile and HardwareProfile.VmSize are preserved in the request.
To switch to FlexProfile by editing the object directly, set FlexProfile.PreferredVMSize and clear HardwareProfile.VmSize before calling Update-AzVM.
To opt out, set FlexProfile to $null and specify a fixed HardwareProfile.VmSize; omit PreferredVMSize.
For a GET-to-update round trip of an existing FlexProfile VM, the cmdlet preserves both FlexProfile and the service-reported HardwareProfile.VmSize in the request without changing the input object.
FlexProfile is a preview feature that requires registration of the Microsoft.Compute/FlexProfileEnabled subscription feature and availability in the target region.
Supported VM families vary by region. Azure validates unsupported placements and empty preferred-size strings.
This command updates the virtual machine, $VirtualMachine, in ResourceGroup11.
The command updates it by using the virtual machine object stored in the $VirtualMachine variable.
To obtain a virtual machine object, use the Get-AzVM cmdlet.
Example 2: Update a virtual machine to disable hyperthreading.
$resourceGroupName = 'Resource Group Name>'
$vmname = 'Virtual Machine Name';
$domainNameLabel = "d1" + $rgname;
$vCPUsCoreInitial = 2;
$vCPUsAvailableInitial = 4;
$vCPUsCore1 = 1;
$vCPUsAvailable1 = 1;
$vmSize = 'Standard_D4s_v4';
$securePassword = ConvertTo-SecureString -String "****" -AsPlainText -Force;
$user = "user";
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);
$vm = New-AzVM -ResourceGroupName $rgname -Name $vmname -Credential $cred -DomainNameLabel $domainNameLabel -Size $vmSize -vCPUCountPerCore $vCPUsCoreInitial -vCPUCountAvailable $vCPUsAvailableInitial;
# The $vm.HardwareProfile.VmSizeProperties.VCPUsPerCore property is 2, and the $vm.HardwareProfile.VmSizeProperties.VCPUsAvailable property is 4.
Update-AzVM -ResourceGroupName $rgname -VM $vm -vCPUCountAvailable $vCPUsAvailable1 -vCPUCountPerCore $vCPUsCore1;
# The $vm.HardwareProfile.VmSizeProperties.VCPUsPerCore property is 1, and the $vm.HardwareProfile.VmSizeProperties.VCPUsAvailable property is 1.
# Hyperthreading is now disabled for this VM.
This example updates a virtual machine so that it is explicitly opted out from any capacity reservation assignment and consumes publicly available capacity instead.
This example overrides the request's fixed size with FlexProfile without changing $vm.
The subscription must be registered for the preview and the VM's region must support it.
Retrieve the VM again to inspect the updated model.
Example 6: Switch to FlexProfile by editing the VM object
When switching a fixed-size VM by directly editing its model, clear VmSize so the request does not contain both a fixed size and FlexProfile.
Using PreferredVMSize as in the previous example handles the outgoing request without these object edits.
Example 7: Preserve FlexProfile in a GET-to-update round trip
For an existing FlexProfile VM, this preserves its FlexProfile and service-reported HardwareProfile.VmSize while updating tags.
Neither property is changed on $vm.
Use the model view from Get-AzVM without Status.
Example 8: Opt out of FlexProfile and use a fixed size
This example clears FlexProfile and requests a fixed size. Do not supply PreferredVMSize when opting out.
Azure validates whether the requested size and placement are supported.
Parameters
-AlignRegionalDisksToVMZone
Specifies whether the regional disks should be aligned/moved to the VM zone. This is applicable only for VMs with placement property set. Please note that this change is irreversible.
Specifies that the virtual machine is explicitly opted out from any capacity reservation assignment.
When set, the virtual machine will not be implicitly or explicitly associated with any capacity reservation and will consume publicly available capacity instead.
EncryptionAtHost property can be used by user in the request to enable or disable the Host Encryption for the virtual machine or virtual machine scale set.
This will enable the encryption for all the disks including Resource/Temp disk at host itself.
Specifies the list of user identities associated with the virtual machine.
The user identity references will be ARM resource IDs in the form: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/identities/{identityName}'
used to make a request conditional for the PUT and other non-safe methods. The server will only return the requested resources if the resource matches one of the listed ETag values. Omit this value to always overwrite the current resource. Specify the last-seen ETag value to prevent accidentally overwriting concurrent changes.
Used to make a request conditional for the GET and HEAD methods. The server will only return the requested resources if none of the listed ETag values match the current entity. Used to make a request conditional for the GET and HEAD methods. The server will only return the requested resources if none of the listed ETag values match the current entity. Set to '*' to allow a new record set to be created, but to prevent updating an existing record set. Other values will result in error from server as they are not supported.
Specifies the maximum price you are willing to pay for a low priority VM/VMSS. This price is in US Dollars. This price will be compared with the current low priority price for the VM size. Also, the prices are compared at the time of create/update of low priority VM/VMSS and the operation will only succeed if the maxPrice is greater than the current low priority price. The maxPrice will also be used for evicting a low priority VM/VMSS if the current low priority price goes beyond the maxPrice after creation of VM/VMSS. Possible values are: any decimal value greater than zero. Example: 0.01538. -1 indicates that the low priority VM/VMSS should not be evicted for price reasons. Also, the default max price is -1 if it is not provided by you.
Starts the operation and returns immediately, before the operation is completed. In order to determine if the operation has successfully been completed, use some other mechanism.
Specifies the preferred VM size for the preview FlexProfile, for example Standard_D4s_v5.
Azure may choose a compatible alternative based on capacity and placement.
In all parameter sets, this parameter overrides the outgoing request's HardwareProfile.VmSize and sets FlexProfile.PreferredVMSize without mutating the input object's hardware profile or FlexProfile.
When omitted, both the input FlexProfile and VmSize are preserved in the request, including the service-reported size of an existing FlexProfile VM.
To switch by editing the object directly, set FlexProfile and clear VmSize. To opt out, clear FlexProfile, set a fixed VmSize, and omit this parameter.
This feature requires preview registration and regional availability. Azure validates unsupported placements and empty strings.
Specifies the SecurityType of the virtual machine. It has to be set to any specified value to enable UefiSettings. By default, UefiSettings will not be enabled unless this property is set.
Specifies the resources and resource groups can be tagged with a set of name-value pairs.
Adding tags to resources enables you to group resources together across resource groups and to create your own views.
Each resource or resource group can have a maximum of 15 tags.
The flag that enables or disables a capability to have one or more managed data disks with UltraSSD_LRS storage account type on the VM.
Managed disks with storage account type UltraSSD_LRS can be added to a virtual machine only if this property is enabled.
Specifies the number of vCPUs available for the VM. When this property is not specified in the request body the default behavior is to set it to the value of vCPUs available for that VM size exposed in api response of List all available virtual machine sizes in a region.
Specifies the vCPU to physical core ratio. When this property is not specified in the request body the default behavior is set to the value of vCPUsPerCore for the VM Size exposed in api response of List all available virtual machine sizes in a region. Setting this property to 1 also means that hyper-threading is disabled.
Specifies a local virtual machine object.
To obtain a virtual machine object, use the Get-AzVM cmdlet.
This virtual machine object contains the updated state for the virtual machine.
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable,
-InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable,
-ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see
about_CommonParameters.
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.