How to migrate a managed Windows Server 2022 image to Shared Image Gallery on Azure

In my previous blog post, we created an offline image of a Windows Server 2022 virtual machine. We’ve uploaded this image to an Azure Managed Image instance. In this blog post, we will be going through the steps to upload this managed image into an Azure Shared Image Gallery.


A prerequisite to continue with this article is that you have already created a managed image.
Not sure how? Please read my previous blog post.

Scripting time

To facilitate the upload process to the Azure Shared Image Gallery, I’ve created this small script that will capture all of the details of your existing image and migrate it to SIG.

The entire script can be downloaded from my GitHub Repo.

Region: Variables

In the region “variables” you need to define some Image specific features like:

  • Image Definition Name
  • Image Definition Publisher
  • Image Definition Offer
  • Image Definition SKU

The variables have already been pre-populated with the required details for the Windows Server 2022 preview image.

Region: Retrieve any existing shared image galleries

In this region, we will check your subscription for any existing SIG. If available, you will receive an out-grid view where you can select your SIG. If not available, the region will provide you with the option to create one.

Region: Create new gallery definition

This region will create a new image gallery definition, this definition states what type of image it will be based on the variables you provided earlier.

Region: Retrieve the managed image.

This is the part where we will gather information about the existing managed image. This region will prompt you with another out-grid view to select your image.

Region: Create new Image version in SIG

Here we provide the details of the image version we are uploading to SIG. Make sure to define your own version number. This version number must be unique within the same image definition.

Region: Verify deployment state

By running this region you can verify the job status

Region: Delete managed Image

This region has been commented out intentionally, you can run this if you are 100% sure you don’t need your managed image anymore.

Deployment Complete

When you head over to your SIG and navigate to the SIG definition, you can see that your new image has been created and has the status of “completed”. You can now start using this image version to make customizations with Azure Image Builder for example.

Deployment Script

# Notes: In the Upload-VHD.ps1 script we have uploaded our image to a managed image, this script will copy the image to a Shared Image Gallery

#region Variables to define our Image

$ImageDefinitionName = "WinSrv2022Datacenter"
$ImageDefinitionPublisher = "microsoftwindowsserver"
$ImageDefinitionOffer = "microsoftserveroperatingsystems-previews"
$ImageDefinitionSKU = "windows-server-2022"


#region Retrieve any existing shared Image Galleries

$gallery = Get-AzGallery | Out-GridView -Title "Select the SIG you want to use" -PassThru
if ($gallery) {
Write-Host "You have selected the following image gallery $($" 
else {
Write-Host "You did not select a SIG, or no SIG is available, please create SIG first."
Write-Host "You can run the following PowerShell example to create a new SIG"
Write-Host '$SIGrg = New-AzResourceGroup -Location "westeurope" -Name "temp-sig-rg"' -ForegroundColor Cyan
Write-Host '$gallery = New-AzGallery -ResourceGroupName $SIGrg.ResourceGroupName -Name "tempsig" -Location "westeurope" -Description "temporary sig"' -ForegroundColor Cyan



#region Create new Gallery Definition

$imageDefinition = New-AzGalleryImageDefinition `
   -GalleryName $gallery.Name `
   -ResourceGroupName $gallery.ResourceGroupName `
   -Location $gallery.Location `
   -Name $ImageDefinitionName `
   -OsState generalized `
   -OsType Windows `
   -Publisher $ImageDefinitionPublisher `
   -Offer $ImageDefinitionOffer `
   -Sku $ImageDefinitionSKU


#region Retrieve the Managed Image

$managedImage = Get-AzImage | Out-GridView -Title "Select the Image you want to upload to the gallery" -PassThru


#region Create new image version in SIG

$region1 = @{Name='West Europe';ReplicaCount=1}
$region2 = @{Name='North Europe';ReplicaCount=2}
$targetRegions = @($region1,$region2)
$job = $imageVersion = New-AzGalleryImageVersion `
   -GalleryImageDefinitionName $imageDefinition.Name `
   -GalleryImageVersionName '1.0.0' `
   -GalleryName $gallery.Name `
   -ResourceGroupName $imageDefinition.ResourceGroupName `
   -Location $imageDefinition.Location `
   -TargetRegion $targetRegions  `
   -SourceImageId $managedImage.Id.ToString() `
   -PublishingProfileEndOfLifeDate '2021-12-31' `


#region Verify deployment state



#region Delete Managed Image

Remove-AzImage `
   -ImageName $managedImage.Name `
   -ResourceGroupName $managedImage.ResourceGroupName


Thank you!

Thank you for reading through this blog post. I hope I have been able to assist you in uploading your Windows Server 2022 managed image to an Azure Shared Image Gallery.

If you encounter any new insights, feel free to drop me a comment or contact me via mail or other social media channels

2 Comments on “How to migrate a managed Windows Server 2022 image to Shared Image Gallery on Azure

Leave a Reply

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

Please reload

Please Wait