Azure – You can now do virtual machine in-place upgrade

As Windows administrator, you know the importance of keeping up with Windows server versions to stay supported and receive updates.

To do so, you usually have 2 options to upgrade your Windows server version:

  • in-place upgrade
  • deploy a new virtual machine running the targeted version and then migrate your workloads and data on this new virtual machine

Well, when running virtual machine on Azure, you only have (or had) the last option.

Good news, you can now perform in-place upgrade on virtual machine running on Azure.

But before you start preparing to perform in-place upgrade, here are few things you need know:

Now you are almost ready. The last steps are:

  • confirm your running workloads/applications are compatible with the new OS version you are upgrading to
  • perform a snapshot – in case you have to roll back
  • prepare the upgrade disk; you will need the Azure PowerShell module (Install-Module -Name Az) – latest version 9.3.0

The in-place upgrade requires the use of an upgrade media attached to the VM as managed disk.

This media can be used on multiple VM but only one at a time.

To create the upgrade media, use the below script

# Connect to Azure and select the subscription


Set-AzContext –Subscription <subscription ID>

# Resource group of the source VM

$resourceGroup = “<name of the resource group where the VM is>”

# Location of the source VM

$location = “<location of the VM>”

# Zone of the source VM, if any

$zone = “”

# Disk name for the that will be created

$diskName = “<upgrade media disk name>”

# Target version for the upgrade – must be either server2022Upgrade or server2019Upgrade

$sku = “server2022Upgrade”

# Common parameters

$publisher = “MicrosoftWindowsServer”

$offer = “WindowsServerUpgrade”

$managedDiskSKU = “Standard_LRS”

# Get the latest version of the special (hidden) VM Image from the Azure Marketplace

$versions = Get-AzVMImage -PublisherName $publisher -Location $location -Offer $offer -Skus $sku | sort-object -Descending {[version] $_.Version}

$latestString = $versions[0].Version

# Get the special (hidden) VM Image from the Azure Marketplace by version – the image is used to create a disk to upgrade to the new version

$image = Get-AzVMImage -Location $location -PublisherName $publisher -Offer $offer -Skus $sku -Version $latestString

# Create Resource Group if it doesn’t exist

if (-not (Get-AzResourceGroup -Name $resourceGroup -ErrorAction SilentlyContinue))


   New-AzResourceGroup -Name $resourceGroup -Location $location


# Create Managed Disk from LUN 0

if ($zone){
     $diskConfig = New-AzDiskConfig -SkuName $managedDiskSKU `
                                    -CreateOption FromImage `
                                    -Zone $zone `
                                    -Location $location
} else {
     $diskConfig = New-AzDiskConfig -SkuName $managedDiskSKU `
                                    -CreateOption FromImage `
                                    -Location $location

Set-AzDiskImageReference -Disk $diskConfig -Id $image.Id -Lun 0

New-AzDisk -ResourceGroupName $resourceGroup `
            -DiskName $diskName `
            -Disk $diskConfig

Then you can attach the upgrade media disk on the virtual machine; it can be done even if the VM is running.


And finally you can start the in-place upgrade process by connecting to the virtual machine and launch the command from the upgrade disk

setup.exe /auto upgrade /dynamicupdate disable

image  image

You can then select the target image

image  image

During the upgrade, the RDP session will be disconnected; you can monitor the progress using the screenshot feature available in the Boot diagnostics


Once you have completed your in-place upgrade, you can proceed to remove the snapshot and the upgrade media.

Leave a Comment

Your email address will not be published. Required fields are marked *