Skip to content

Instantly share code, notes, and snippets.

@echu2013
echu2013 / CleanAppxsBeforeSysprep.ps1
Created January 28, 2025 14:40
Removes Appx installed for users but not provisioned system-wide, which prevents Sysprep correct operation
# After trying several approches only, which in general tells you to launch sysprep several times or removing everything
# I found this the most precise way to do.
# Otherwise u are stuck with a try-and-error process which is time consuming (launch, view error, remove, retry, etc)
# Get APPX Provisioned system-wide
$pkgsprovisioned= Get-AppxProvisionedPackage -Online
# Get ALLUSERS APPX which are NOT provisioned system-wide and NonRemovable flag is False
$pkgs= Get-AppxPackage -AllUsers | Where-Object { $_.Name -notin $pkgsprovisioned.DisplayName -and $_.NonRemovable -eq $false}
# Remove those APPX
$pkgs | Remove-AppxPackage -ErrorAction SilentlyContinue