0

I'm trying to get my universal uninstaller working. Here is my code:

CLS

$Software = "Zoom"
$Filter = "*" + $Software + "*"
$Program = $ProgUninstall = $FileUninstaller = $FileArg = $NULL

try 
{
    if (Test-Path -Path "HKLM:\SOFTWARE\WOW6432Node") 
    {
        $programs = Get-ItemProperty -Path "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" -ErrorAction Stop
    }

    $programs += Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*" -ErrorAction Stop
    $programs += Get-ItemProperty -Path "Registry::\HKEY_USERS\*\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*" -ErrorAction SilentlyContinue
} 
catch 
{
    Write-Error $_
    break
}

foreach($Program in $Programs)
{
    $ProgDisplayName = $Program.DisplayName
    $ProgUninstall = $Program.UninstallString

    if($ProgDisplayName -like $Filter)
    {
        #$Program

        $aux = $ProgUninstall -split @('\.exe'),2,[System.StringSplitOptions]::None
        $Uninstaller = (cmd /c echo $($aux[0].TrimStart('"').TrimStart("'") + '.exe')).Trim('"')
        $UninsParams = $aux[1].TrimStart('"').TrimStart("'").Trim().split(' ',[System.StringSplitOptions]::RemoveEmptyEntries)
        if($aux -notlike "param 0 = *")
        {
           # $UninsParams = $aux[1].TrimStart('"').TrimStart("'").Trim().split(' ',[System.StringSplitOptions]::RemoveEmptyEntries)
        }

        $Uninstaller
        $UninsParams

       # . $Uninstaller $UninsParams | Where-Object { $_ -notlike "param 0 = *" }
    }
}

In my example I'm trying to get an output for Zoom. I have the Zoom client installed and the Zoom Outlook plugin installed.

Here is the output of the program:

DisplayName  : Zoom Outlook Plugin
PSPath       : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{0B76DE11-5937-4491-A66A-617E42170AFF}
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall
PSChildName  : {0B76DE11-5937-4491-A66A-617E42170AFF}
PSDrive      : HKLM
PSProvider   : Microsoft.PowerShell.Core\Registry

You cannot call a method on a null-valued expression.
At line:34 char:9
+         $UninsParams = $aux[1].TrimStart('"').TrimStart("'").Trim().s ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
 

AuthorizedCDFPrefix : 
Comments            : Zoom
Contact             : Zoom Video Communications, Inc.
DisplayVersion      : 5.4.58891
HelpLink            : https://support.zoom.us/home
HelpTelephone       : 
InstallDate         : 20201119
InstallLocation     : 
InstallSource       : C:\temp\Zoom\
ModifyPath          : MsiExec.exe /X{3109C49B-F5E4-4FEC-8F6F-EC5E4626B361}
NoModify            : 1
Publisher           : Zoom
Readme              : 
Size                : 
EstimatedSize       : 122109
UninstallString     : MsiExec.exe /X{3109C49B-F5E4-4FEC-8F6F-EC5E4626B361}
URLInfoAbout        : https://zoom.us
URLUpdateInfo       : 
VersionMajor        : 5
VersionMinor        : 4
WindowsInstaller    : 1
Version             : 84207115
Language            : 1033
DisplayName         : Zoom
PSPath              : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{3109C49B-F5E4-4FEC-8F6F-EC5E4626B36
                      1}
PSParentPath        : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall
PSChildName         : {3109C49B-F5E4-4FEC-8F6F-EC5E4626B361}
PSDrive             : HKLM
PSProvider          : Microsoft.PowerShell.Core\Registry

Part of the problem from what I can tell is the Zoom Outlook plugin doesn't have any uninstall strings associated with it. I'm assuming it's just part of the Zoom Client (even though it's a seperate installer). What I'm trying to do is get this code to work without throwing any errors or displaying false positives.

Here is the output of my 2 parms "$Uninstaller" and "$UninsParams"

You cannot call a method on a null-valued expression.
At line:34 char:9
+         $UninsParams = $aux[1].TrimStart('"').TrimStart("'").Trim().s ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
 
.exe
/X{3109C49B-F5E4-4FEC-8F6F-EC5E4626B361}
MsiExec.exe
/X{3109C49B-F5E4-4FEC-8F6F-EC5E4626B361}

Thanks in advance!

1 Answer 1

0

The problem here is that since the Zoom Client Plugin doesn't have an uninstall script, your -split operation evaluates to a single empty string, and $aux[1] therefore evaluates to $null, hence the error message.

You could filter out entries without a valid UninstallString:

foreach($Program in $Programs |Where-Object UninstallString -match '\.exe')
{
    # ... now you don't need to worry about this not resulting in two strings
    $aux = $ProgUninstall -split @('\.exe'),2,[System.StringSplitOptions]::None
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.