'Uninstall application using Powershell

I have a 3rd party agent installed on my virtual machines that I need to remove using Powershell.

It shows up in control panel, add/remove programs but does not show up using either get-wmiobject or the get-itemproperty hklm uninstall registry key path:

get-itemproperty HKLM:\\software\microsoft\windows\currentversion\uninstall* | select-object displayname, displayversion, publisher

Anyone else know a way that I can remove it using a script?



Solution 1:[1]

In the future include any code you've tried, even if it doesn't work! Just listing the names of the commands you tried isn't very useful as we can't see what you're doing so have to guess. You've had comments and an answer that wasn't relevant because of this.


Now you've finally shown your code (I've edited your answer to include it as it was hidden in a comment), I can see that you're only checking one of the two Uninstall key locations.

On a 64bit OS (most computers these days) there are two places for these:

  • HKLM:\SOFTWARE\Microsoft [..]
  • HKLM:\SOFTWARE\Wow6432Node\Microsoft [..]

Here's an example on how to search them for firefox:

$RegPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"

$app = Get-ChildItem -Path $RegPath | Get-ItemProperty | Where-Object {$_.DisplayName -match "firefox" }

You can then execute either $app.QuietUninstallString or $app.UninstallString - you may not have both available it depends on the application.

Solution 2:[2]

This should work if was an msi installer (powershell 5.1). Powershell 7 does not support msi or programs providers.

get-package *softwarename* | uninstall-package

Or with the programs provider, you could probably see the uninstallstring, but have to add more for a silent uninstall, like "/S".

get-package *softwarename* | % { & $_.metadata['uninstallstring'] /S } 

Solution 3:[3]

Just to add to Henrycarteruk's post, you can pipe the commands to cmd to execute the uninstall strings.

$app.QuietUninstallString | cmd

Solution 4:[4]

Try:

 $installedMsiObject = Get-WmiObject -Class Win32_Product | Where-Object { $_.PackageName -like "*YourPkgName* }
 if ($installedMsiObject) {
    try {
       $installedMsiObject.UnInstall() | Out-Null
    }
    catch {
       Write-Error "Error occurred: $_"
    }
 }

Solution 5:[5]

This is an old post but responding here in case it helps somebody else. I beat my head on this for days ...

In addition to the [2] HKLM registry paths referenced above (one for 32-bit registry and the other for 64-bit registry), you also need to look at HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall in order to query "per-user" installs. Applications like Chrome, MS Teams, Zoom, ReadyTalk Desktop, etc) install by default as "per-user". You will not find the installer / uninstaller information under HKLM.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 henrycarteruk
Solution 2
Solution 3 user18357922
Solution 4 Moerwald
Solution 5 Jimmy Cleveland