Share via

Issues when creating an image to add to the Azure compute galleries, so i can use AVD with session host configurations

Justin Losier 0 Reputation points
2026-05-06T15:42:56.2066667+00:00

Hi,

I'm trying to build an image from the latest Win Multisession + M365 apps that i would like to capture to the image gallery so i can scale my AVD environment with Session host configurations.

I do disable bit locker, appx apps, and a few things that blocks sysprep usually but when i run sysprep, it goes through without errors in the setupact.log file but the image stays in limbo where i can't use it in the image gallery or reboot it to fix it.

It says stopped if i click on the VM for the status. but in the VM liste, it is stuck at Updating for status.

To see the logs, i have to delete the vm without the disk and mount that disk to another VM.

I tried about 10 times

This is my prep script:

<#

AVD IMAGE PREPARATION SCRIPT (LOCALADMIN SAFE)

Windows 11 Enterprise Multi‑Session  

#>

Write-Host "=== AVD IMAGE PREP SCRIPT START ===" -ForegroundColor Cyan

-------------------------------

1. Disable BitLocker (staged encryption bug)

-------------------------------

Write-Host "Disabling BitLocker protectors..." -ForegroundColor Yellow

manage-bde -protectors -disable C:

manage-bde -off C:

Start-Sleep -Seconds 5

-------------------------------

2. Remove Sysprep-breaking AppX packages

-------------------------------

Write-Host "Removing problematic AppX packages..." -ForegroundColor Yellow

$AppxToRemove = @(

"Microsoft.People",

"Microsoft.MicrosoftOfficeHub",

"Microsoft.Xbox.TCUI",

"Microsoft.XboxGamingOverlay",

"Microsoft.XboxIdentityProvider",

"Microsoft.XboxSpeechToTextOverlay",

"Microsoft.GamingApp",

"Microsoft.GetHelp",

"Microsoft.Getstarted",

"Microsoft.WindowsFeedbackHub",

"Microsoft.WindowsMaps",

"Microsoft.Microsoft3DViewer",

"Microsoft.MSPaint",

"Microsoft.WindowsSoundRecorder",

"Microsoft.549981C3F5F10",   # Cortana remnants

"Clipchamp.Clipchamp",

"Microsoft.OutlookForWindows",

"MicrosoftTeams"

)

foreach ($pkg in $AppxToRemove) {

Get-AppxPackage -Name $pkg -AllUsers | Remove-AppxPackage -AllUsers -ErrorAction SilentlyContinue

Get-AppxProvisionedPackage -Online | Where-Object {$_.DisplayName -eq $pkg} | Remove-AppxProvisionedPackage -Online -ErrorAction SilentlyContinue

}

-------------------------------

3. Stop services that block Sysprep

-------------------------------

Write-Host "Stopping services that interfere with Sysprep..." -ForegroundColor Yellow

$ServicesToStop = @(

"wuauserv",      # Windows Update

"UsoSvc",

"TrustedInstaller",

"Sense",         # MDE

"DiagTrack",

"SysMain"

)

foreach ($svc in $ServicesToStop) {

Stop-Service -Name $svc -Force -ErrorAction SilentlyContinue

Set-Service -Name $svc -StartupType Manual -ErrorAction SilentlyContinue

}

-------------------------------

4. Remove provisioning packages (Windows 11 syntax)

-------------------------------

Write-Host "Removing provisioning packages..." -ForegroundColor Yellow

Get-ProvisioningPackage | Remove-ProvisioningPackage -ErrorAction SilentlyContinue

-------------------------------

5. Final message before Sysprep

-------------------------------

Write-Host "`n=== PREP COMPLETE ===" -ForegroundColor Green

Azure Virtual Desktop
Azure Virtual Desktop

A Microsoft desktop and app virtualization service that runs on Azure. Previously known as Windows Virtual Desktop.


1 answer

Sort by: Most helpful
  1. AI answer

    2026-05-06T15:43:18.26+00:00

    Sysprep and image capture for Azure Virtual Desktop session hosts must follow specific requirements; otherwise the VM can end up in a stuck “Updating” state and the image can’t be used.

    Key points based on the documented guidance:

    1. Sysprep options for images used in Azure Compute Gallery
      • For Dev Box and AVD scenarios, the generalized VM must be sysprepped with exactly these options:
        • /generalize /oobe /mode:vm
      • When capturing manually from the VM, add /shutdown so the VM powers off cleanly before capture:
             C:\Windows\System32\Sysprep\sysprep.exe /generalize /oobe /mode:vm /shutdown
        
      • If using an automated builder (for example, Packer or Azure VM Image Builder), use the quiet options and let the tool control shutdown:
             C:\Windows\System32\Sysprep\sysprep.exe /generalize /oobe /mode:vm /quiet /quit
        
      • The /mode:vm flag is specifically called out to avoid long driver searches and first‑boot delays and is also recommended when overriding the default Sysprep command in Azure VM Image Builder.
    2. Avoid running Sysprep too many times
      • VM Image Builder and manual customization both rely on Sysprep. There is a documented limit on how many times Sysprep can be run on a single Windows image. After that limit is reached, the image must be recreated from a fresh base. If the same base VM has been generalized repeatedly during testing (around 10 attempts as described), this can contribute to failures or images that do not provision correctly.
    3. Let Azure VM Image Builder handle Sysprep when possible
      • When using Azure VM Image Builder to create an image version in an Azure Compute Gallery, Sysprep is run automatically with a generic command. This command can be overridden to add /mode:vm, but there is no need to run Sysprep manually inside the VM beforehand.
      • Overriding the Sysprep command is the supported way to ensure /mode:vm is used and to avoid long “Please wait for the Windows Modules Installer” delays on first logon.
    4. Image requirements and optimizations for Azure Compute Gallery
      • For images intended for Dev Box/AVD session hosts in an Azure Compute Gallery, the following are required or recommended:
        • Sysprep with /generalize /oobe /mode:vm.
        • Enable Read/Write cache on the OS disk of the image (properties.storageProfile.osDisk.caching = ReadWrite).
        • Enable nested virtualization features (Virtual Machine Platform) in the base image:
                 Enable-WindowsOptionalFeature -FeatureName VirtualMachinePlatform -Online
          
        • Clean up the component store to reduce provisioning time:
                 DISM.exe /Online /Cleanup-Image /StartComponentCleanup
          
        • Disable reserved storage:
                 DISM.exe /Online /Set-ReservedStorageState /State:Disabled
          
        • Run defrag and chkdsk during image creation and then disable scheduled defrag/chkdsk tasks.
    5. Handling Store apps and Sysprep failures
      • Sysprep can fail or behave unexpectedly if Microsoft Store apps are removed or updated incorrectly. The documented, supported method is:
        • Identify installed AppX packages and their user bindings:
                 Import-Module Appx
                 Import-Module Dism
                 Get-AppxPackage -AllUsers | Where PublisherId -eq 8wekyb3d8bbwe | \
                   Format-List -Property PackageFullName,PackageUserInformation
          
        • For packages that show as Installed for any user, either remove those user profiles or log on as those users and then:
                 Remove-AppxPackage -Package <packagefullname>
                 Remove-AppxProvisionedPackage -Online -PackageName <packagefullname>
          
      • This approach removes both the per‑user package and the provisioning and is the supported way to avoid Sysprep issues related to Store apps.
    6. Recommended end‑to‑end approach for AVD session host images
      • Start from a fresh marketplace image (for example, Windows 10/11 Enterprise multi‑session) rather than reusing a heavily modified or repeatedly sysprepped VM.
      • Apply required Windows updates and AVD agents, then perform the recommended optimizations (component cleanup, reserved storage disable, Virtual Machine Platform, etc.).
      • Use Azure VM Image Builder to create and distribute an image version into an Azure Compute Gallery, letting it run Sysprep automatically, optionally overriding the Sysprep command to include /mode:vm.
      • Capture the generalized VM into the Azure Compute Gallery and then use that gallery image for AVD session host scaling.

    Following these documented Sysprep options and image requirements, and avoiding repeated Sysprep runs on the same base image, prevents the “stuck Updating” state and produces images that provision and start correctly as AVD session hosts.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.