From 04130231ff24089cf3ef79ae6653d4010c5f0423 Mon Sep 17 00:00:00 2001 From: CodingWonders <101426328+CodingWonders@users.noreply.github.com> Date: Fri, 28 Jun 2024 16:42:48 +0200 Subject: [PATCH] Update Invoke-MicroWin-Helper.ps1 (#2192) Added Try-Catch block for AppX package removal --- functions/private/Invoke-MicroWin-Helper.ps1 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/functions/private/Invoke-MicroWin-Helper.ps1 b/functions/private/Invoke-MicroWin-Helper.ps1 index 2f8011a2..c5fdff8a 100644 --- a/functions/private/Invoke-MicroWin-Helper.ps1 +++ b/functions/private/Invoke-MicroWin-Helper.ps1 @@ -159,7 +159,13 @@ function Remove-ProvisionedPackages([switch] $keepSecurity = $false) { $status = "Removing Provisioned $($appx.PackageName)" Write-Progress -Activity "Removing Provisioned Apps" -Status $status -PercentComplete ($counter++/$appxProvisionedPackages.Count*100) - Remove-AppxProvisionedPackage -Path $scratchDir -PackageName $appx.PackageName -ErrorAction SilentlyContinue + try { + Remove-AppxProvisionedPackage -Path $scratchDir -PackageName $appx.PackageName -ErrorAction SilentlyContinue + } + catch { + Write-Host "Application $($appx.PackageName) could not be removed" + continue + } } Write-Progress -Activity "Removing Provisioned Apps" -Status "Ready" -Completed }