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,15 +367,41 @@ function RemoveApps {
|
|||||||
# Remove installed app for all existing users
|
# Remove installed app for all existing users
|
||||||
if ($WinVersion -ge 22000){
|
if ($WinVersion -ge 22000){
|
||||||
# Windows 11 build 22000 or later
|
# Windows 11 build 22000 or later
|
||||||
Get-AppxPackage -Name $app -AllUsers | Remove-AppxPackage -AllUsers -ErrorAction Continue
|
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 {
|
else {
|
||||||
# Windows 10
|
# 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
|
# Remove provisioned app from OS image, so the app won't be installed for any new users
|
||||||
Get-AppxProvisionedPackage -Online | Where-Object { $_.PackageName -like $app } | ForEach-Object { Remove-ProvisionedAppxPackage -Online -AllUsers -PackageName $_.PackageName }
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user