7-Zip uninstall practices

I need to deploy the latest version of 7-Zip. Looking around, it seems it’s best to uninstall before installing because there can be x86 and x64 versions installed, some by .MSI and some by .EXE. Remove-MSIApplications will only work for those installed via msiexec/.MSI, right? What is the best way to approach this? Query the registry for the UninstallString and use Execute-Process, or is there another preferred built-in method to remove all installations of a given product regardless of install method?

Ha!, Well that’s a co-incidence, I discovered a repository of Intune Remedaition scripts yesterday evening:

Even if you don’t have Intune, with a little modification the code from the Uninstall-Application would probably suit this right down to the ground

This checks the registry Uninstall keys for an app (or list of apps) defined in the $blacklistapps variable (line 16).

This may go some way to solving your issue.

You also can use some kind of this in addition to “Remove-MSIApplications” : [Found on Silentinstallhq(dot)com]

    ## Remove Any Existing Versions of 7-Zip (EXE)
    $AppList = Get-InstalledApplication -Name '7-Zip'        
    ForEach ($App in $AppList)
    {
    If($App.UninstallString)
    {
    $UninstPath = $($App.UninstallString).Replace('"','')       
    If(Test-Path -Path $UninstPath)
    {
    Write-log -Message "Found $($App.DisplayName) $($App.DisplayVersion) and a valid uninstall string, now attempting to uninstall."
    Execute-Process -Path $UninstPath -Parameters '/S'
    Start-Sleep -Seconds 5
    }
    }
    }

FYI: PSADT has a function to retrieve Uninstallation information with the Get-InstalledApplication function

Thank you all! I’ve very new to PSADT. Our workstation group uses it for nearly every deployment and I was just recently exposed to it.

1 Like

Maybe a (very) dumb Question: but how do i use that for an Uninstall?