From 21cafbb931dfb5df70ac7f2dc8a5614a20f2950f Mon Sep 17 00:00:00 2001 From: David Yoder Date: Wed, 23 Aug 2023 15:10:45 -0400 Subject: [PATCH] handle errors accessing registry in Uninstall-MSI --- Tools.ps1 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Tools.ps1 b/Tools.ps1 index a1d2e29..a5efc2b 100644 --- a/Tools.ps1 +++ b/Tools.ps1 @@ -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 = @()