mirror of
https://github.com/Raphire/Win11Debloat.git
synced 2025-11-17 11:06:18 +00:00
Improve app removal errorhandling,
Additionally added a workaround for the issue described in #131, to ensure the app is atleast uninstalled for the current user while we figure out how to fix app removal for all users.
This commit is contained in:
@@ -367,16 +367,42 @@ function RemoveApps {
|
||||
# Remove installed app for all existing users
|
||||
if ($WinVersion -ge 22000){
|
||||
# Windows 11 build 22000 or later
|
||||
try {
|
||||
Get-AppxPackage -Name $app -AllUsers | Remove-AppxPackage -AllUsers -ErrorAction Continue
|
||||
}
|
||||
catch {
|
||||
Write-Host "Unable to remove $app for all users" -ForegroundColor Yellow
|
||||
Write-Host $psitem.Exception.StackTrace -ForegroundColor Gray
|
||||
}
|
||||
}
|
||||
else {
|
||||
# Windows 10
|
||||
Get-AppxPackage -Name $app -PackageTypeFilter Main, Bundle, Resource -AllUsers | Remove-AppxPackage -AllUsers
|
||||
try {
|
||||
Get-AppxPackage -Name $app | Remove-AppxPackage -ErrorAction SilentlyContinue
|
||||
}
|
||||
catch {
|
||||
Write-Host "Unable to remove $app for current user" -ForegroundColor Yellow
|
||||
Write-Host $psitem.Exception.StackTrace -ForegroundColor Gray
|
||||
}
|
||||
|
||||
try {
|
||||
Get-AppxPackage -Name $app -PackageTypeFilter Main, Bundle, Resource -AllUsers | Remove-AppxPackage -AllUsers -ErrorAction SilentlyContinue
|
||||
}
|
||||
catch {
|
||||
Write-Host "Unable to remove $app for all users" -ForegroundColor Yellow
|
||||
Write-Host $psitem.Exception.StackTrace -ForegroundColor Gray
|
||||
}
|
||||
}
|
||||
|
||||
# Remove provisioned app from OS image, so the app won't be installed for any new users
|
||||
try {
|
||||
Get-AppxProvisionedPackage -Online | Where-Object { $_.PackageName -like $app } | ForEach-Object { Remove-ProvisionedAppxPackage -Online -AllUsers -PackageName $_.PackageName }
|
||||
}
|
||||
catch {
|
||||
Write-Host "Unable to remove $app from windows image" -ForegroundColor Yellow
|
||||
Write-Host $psitem.Exception.StackTrace -ForegroundColor Gray
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Write-Output ""
|
||||
|
||||
Reference in New Issue
Block a user