Skip to content

Instantly share code, notes, and snippets.

@echu2013
Created January 28, 2025 14:40
Show Gist options
  • Save echu2013/5aa416d4269d50e4d5edcaf01cb00acb to your computer and use it in GitHub Desktop.
Save echu2013/5aa416d4269d50e4d5edcaf01cb00acb to your computer and use it in GitHub Desktop.
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
# Now you can launch sysprep
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment