Resolving Sysprep error – “app was installed for a user, but not provisioned for all users”

 I recently ran into an issue with a client when trying to capture a new AVD image. When trying to sysprep the VM before image capture, we were receiving the below error – “Sysprep was not able to validate your Windows Installation. Review the log file at %WINDIR%\System32\Sysprep\Panther\setupact.log”  

 The above error on its own is not very helpful, but if we open the referenced log file, we can see several errors. Specifically, can can see it’s complaining about the Microsoft.Winget.Source app being installed for a user, but not provisioned for all users and this package won’t function properly in a sysprep image.

 After a little searching, I found this MS learn page, which contained almost the exact issue we were having. Specifically, this section. This lays out the issue pretty clearly. So, to resolve this issue, we need to identify the problematic app in the log, which in our case is Microsoft.Winget.Source_2023.928.502.235_neutral_8wekyb3d8bbwe

 To confirm the installation status, we can run the below command from an admin PowerShell prompt:

Get-AppxPackage -AllUsers | Where PublisherId -eq 8wekyb3d8bbwe | Format-List -Property PackageFullName,PackageUserInformation 

 If we look through the output, we can see the app that is throwing the error, and we also see that it shows installed for the user that was trying to execute sysprep: 

  

Next, we need to remove the package using the below command. If you’re not running the command as the user you’re trying to run sysprep with, you can add the -allusers parameter  

Remove-AppxPackage -Package Microsoft.Winget.Source_2023.928.502.235_neutral__8wekyb3d8bbwe 

  Or

Remove-AppxPackage -allusers -Package Microsoft.Winget.Source_2023.928.502.235_neutral__8wekyb3d8bbwe 

And then the provisioning package with: 

Remove-AppxProvisionedPackage -Online -PackageName Microsoft.Winget.Source_2023.928.502.235_neutral__8wekyb3d8bbwe 

After the app and provisioningpackage have been removed, you can sysprep your image without errors.