Files
winutil/functions/private/Remove-WinUtilAPPX.ps1
T

34 lines
1.1 KiB
PowerShell
Raw Normal View History

+3
2023-03-07 12:28:00 -08:00
function Remove-WinUtilAPPX {
<#
2023-10-19 17:12:55 -05:00
.SYNOPSIS
Removes all APPX packages that match the given name
+3
2023-03-07 12:28:00 -08:00
2023-10-19 17:12:55 -05:00
.PARAMETER Name
The name of the APPX package to remove
.EXAMPLE
+3
2023-03-07 12:28:00 -08:00
Remove-WinUtilAPPX -Name "Microsoft.Microsoft3DViewer"
2023-10-19 17:12:55 -05:00
+3
2023-03-07 12:28:00 -08:00
#>
param (
$Name
)
try {
+3
2023-03-07 12:28:00 -08:00
Write-Host "Removing $Name"
Get-AppxPackage "*$Name*" | Remove-AppxPackage -ErrorAction SilentlyContinue
Get-AppxProvisionedPackage -Online | Where-Object DisplayName -like "*$Name*" | Remove-AppxProvisionedPackage -Online -ErrorAction SilentlyContinue
} catch [System.Exception] {
+12
2023-11-28 16:11:11 -06:00
if ($psitem.Exception.Message -like "*The requested operation requires elevation*") {
+3
2023-03-07 12:28:00 -08:00
Write-Warning "Unable to uninstall $name due to a Security Exception"
} else {
+3
2023-03-07 12:28:00 -08:00
Write-Warning "Unable to uninstall $name due to unhandled exception"
2023-10-19 17:12:55 -05:00
Write-Warning $psitem.Exception.StackTrace
+3
2023-03-07 12:28:00 -08:00
}
} catch {
+3
2023-03-07 12:28:00 -08:00
Write-Warning "Unable to uninstall $name due to unhandled exception"
2023-10-19 17:12:55 -05:00
Write-Warning $psitem.Exception.StackTrace
+3
2023-03-07 12:28:00 -08:00
}
}