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:

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:

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 }