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:
Jeffrey
2024-10-02 00:42:22 +02:00
committed by GitHub
parent 63a017d620
commit 46d1d2bab7

View File

@@ -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 ""