If Azure Devops pipeline for capture of new image version from golden image VM fails, and the failed pipeline is caused by failing “VM Sealing” (also called sysprep), most likely it is because of AppX packages on the image VM, that blocks the sysprep from completing.

You can take a snapshot of the image VM, to have a safe backup of the image VM. Then you can try manual sysprep – this will break the image VM if sysprep is successful and you must delete the image VM, and restore from snapshot. But this can outline if sysprep fails – because if sysprep fails, sysprep closes and you can browse the sysprep folder (C:\windows\system32\sysprep\panther) on the image VM to read the logs (setupact.log). Often the logs will contain errors about AppX package that is not staged for all users on the VM.
To quickly remediate this, run the 2 lines of PowerShell code (as administrator). The commands will often give a lot of red errors, but it will do the job.
Get-AppxPackage -AllUser | Remove-AppxPackage
Get-AppxPackage -AllUser | Remove-AppxProvisionedPackage -Online
Afterwards, capture the image VM again.
If it stills will not capture, it may be because some packages are not removing even if above commands are executed.
Then writing this article, the reason why above commands does not remove the packages remain unknown, but below description solves the issue and also gives insights on how to troubleshoot sysprep issues that is useful in other scenarios aswell.
IMPORTANT
TAKE A SNAPSHOT OF THE IMAGE VM BEFORE PROCEEDING.
- TAKE A SNAPSHOT OF THE IMAGE VM BEFORE PROCEEDING.
- Sign in to the AVD image VM
- Run this comand in Powershell, running as administrator:
Start-Process -FilePath "$env:windir\System32\Sysprep\sysprep" -ArgumentList "/generalize /oobe /shutdown /mode:vm" -Wait
- See that it fails. Now open the setupact file and analyze.
- In this example, it was due to danish language pack appX version that blocked. (Picture from another common error seen before):
- Run Powershell command to remove this appx package, from a Powershell terminal running as administrator.
Get-AppXPackage -All Microsoft.LanguageExperiencePackda-dk | Remove-AppXPackage -AllUsers
7. now try to capture the AVD image VM again using the Azure DevOps pipeline
Comments