We have hundreads of Azure Virtual Desktop (AVD) VMs across multiple AVD Host Pools deployed via the Terraform. We have tested to upgrade those VMs via the Intune Or SSCM.
However, OS gets updated on the AVD hosts but the Source image details
does not changes.
This is an issue for the terraform managed resources as next deployment plans for destruction and recreate.
I am using below Azure Poweshell script to update the StorageProfile.ImageReference
property on the VMs. But its not working. Any alternate solution for this?
$sub_id = "xxx"
Set-AzContext -SubscriptionId $sub_id
Import-module Az.Resources
Import-module Az.Compute
$rg_name = "my-rg"
$vm_name = "my-vm"
$newImageReference = New-Object Microsoft.Azure.Management.Compute.Models.ImageReference -Property @{
Publisher = "microsoftwindowsdesktop"
Offer = "windows-11"
Sku = "win11-23h2-ent"
Version = "latest"
}
$vm = Get-AzVM -ResourceGroupName $rg_name -Name $vm_name
$vm.StorageProfile.imageReference = $newImageReference
Update-AzVM -ResourceGroupName $rg_name -VM $vm
Update-AzVM: Changing property 'imageReference' is not allowed.
ErrorCode: PropertyChangeNotAllowed
ErrorMessage: Changing property 'imageReference' is not allowed.
ErrorTarget: imageReference
StatusCode: 409
ReasonPhrase:
OperationID : 5e0606da-3045-4154-be2e-23cd3b356edb
Update the ImageReference property of multiple Azure Virtual Desktop (AVD) VM Hosts
You cannot update ImageReference
property for existing Azure VM's, if you want to change it to different Image, you need the create the new VM
, but the same feature is available for VMSS.You can follow the MS Doc for changing the image reference
As an alternate approach, you can delete the VM and keeping the network configuration (VNet, NIC, Public IP). If you have any data disks attached to the existing VM, just detach them and attach them to the new VM after creation.
Reference: Is it possible to re-deploy Azure VM with different image by Micah McKittrick
Azure VM - Update Azure VM Image to New One by Prrudram-MSFT