handle errors accessing registry in Uninstall-MSI

This commit is contained in:
2023-08-23 15:10:45 -04:00
parent 01a04a1127
commit 21cafbb931
+5 -2
View File
@@ -806,8 +806,11 @@ Function Get-GUIDFromMSIUninstallString ([string]$str) {
Function Uninstall-MSI ([Parameter(ValueFromPipeline=$true)][string[]]$APP_NAMES) {
PROCESS {
# Get all of the uninstall registry keys
$UNINSTALL_KEYS = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
$UNINSTALL_KEYS += Get-ChildItem -Path HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall
$UNINSTALL_KEYS = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall -ErrorAction SilentlyContinue
$UNINSTALL_KEYS += Get-ChildItem -Path HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall -ErrorAction SilentlyContinue
# Exit if we can't find any software at all
If ( $UNINSTALL_KEYS.Length -eq 0 ) { LogErr "Attempted to uninstall ${APP_NAMES} but could not find any installed apps in the Windows Registry" ; Return }
# Array to store custom objects about each installed MSI app
$INSTALLED_APPS = @()