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
|
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
|
2023-03-07 12:28:00 -08:00
|
|
|
Remove-WinUtilAPPX -Name "Microsoft.Microsoft3DViewer"
|
2023-10-19 17:12:55 -05:00
|
|
|
|
2023-03-07 12:28:00 -08:00
|
|
|
#>
|
|
|
|
|
param (
|
|
|
|
|
$Name
|
|
|
|
|
)
|
|
|
|
|
|
2024-08-06 23:35:17 +03:00
|
|
|
try {
|
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
|
2024-08-06 23:35:17 +03:00
|
|
|
} catch [System.Exception] {
|
2023-11-28 16:11:11 -06:00
|
|
|
if ($psitem.Exception.Message -like "*The requested operation requires elevation*") {
|
2023-03-07 12:28:00 -08:00
|
|
|
Write-Warning "Unable to uninstall $name due to a Security Exception"
|
2024-08-06 23:35:17 +03:00
|
|
|
} else {
|
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
|
2023-03-07 12:28:00 -08:00
|
|
|
}
|
2024-08-06 23:35:17 +03:00
|
|
|
} catch {
|
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
|
2023-03-07 12:28:00 -08:00
|
|
|
}
|
2024-08-06 23:35:17 +03:00
|
|
|
}
|