Orange County, Tustin, CA 92780

How to Uninstall MSI Using PowerShell and an RMM

How to Uninstall MSI Using PowerShell and an RMM

Now and then, you come across the need to remove an application either by doing an MSI Uninstall or EXE uninstall. While you can manually uninstall an application one by one for a small number of computers, if you have multiple computers, from a few to hundreds, it's not practical to visit every machine either in person or remotely, not to mention coordinate time with the end user. You'll need a quick way to uninstall the software, and one of the quickest ways is to use PowerShell. 

The Problem

This particular problem I came across was for removing Adobe Acrobat Pro 2017 but will work for everything where an MSI was used. While the installer used an EXE, the software folder contained an MSI installer once the software was installed. To our surprise, we realized that Adobe had packaged the MSI within the EXE installer, making our removal process easy to do. Not all companies will do this, but I suggest you look at the installed application folder within your C drive or wherever you installed your application and look for an MSI file. It will save you a ton of time trying to remove it if you find it and test its removal process. 

The Fix(es)

While you can deploy this fix in multiple ways using GPO, SCCM, an RRM tool, etc., I'll focus on the following methods: Using only Powershell and N-Able's RMM (new name as of 2022 is N-able N-sight).

Additional InformationAdditional Information:
To give where credit is due, the original fix for this came from Error: Uninstall an MSI and msiexec fails asking for path of old MSI – Venafi Customer Support

To ensure we can use this method, we'll run a Powershell command to retrieve all the software recognized by the command on the system, and if the software title is in the list, we can proceed with the next step. If the software title does not appear, this method will not work for you.

Fix # 1: Pure Powershell 5

Assumption(s)Warning(s):
This method only works with Powershell 5 and the Get-Wmiobject cmdlet. I tried using PowerShell 7, but the cmdlet was removed by design as described by this Microsoft article.

First, we will get a list of all the software installed on our selected test machine where we know the software is installed. Please run the following code below and find the exact name of the software we're trying to uninstall.

 Get-WmiObject -Class Win32_Product | select name | sort

You'll get the following output:

get-wmiobject for uninstallation of software

Now that we have the exact name of the software title type it into the line below by replacing the "Your_App" text.

 $app = Get-WmiObject -Class Win32_Product -Filter "Name = 'YOUR_APP'"
 $app.Uninstall()

That's it. The software title should now be uninstalled.

Example of what the script looks like in Notepad. Notice the single and double quotes for the name. 

PowerShell script uninstall software

Fix # 2: Pure Powershell 7

Additional InformationAdditional Information:
Notice this uses the Get-Ciminstance instead of the Get-WmiObject cmdlet.

Again, we'll run the following code to get a list of software but this time using Powershell 7.

 Get-WmiObject -Class Win32_Product | select name | sort 

Which produces a similar list as above under Powershell 5 but notice there are some differences under Powershell 7. I suspect Microsoft made changes in this updated cmdlet for improved recognition of installed software. 

get-wmiobject for uninstalling software under PowerShell

Again, now that we have the exact name of the application from the output, copy that and replace the 'YOUR_APP' text below.

 $app = Get-CimInstance -Class Win32_Product -Filter "Name = 'YOUR_APP'"
 $app.Uninstall()

That should uninstall the application.

Fix # 3: PowerShell with N-able N-sight RMM

Sure, the above works for one or a few machines if you are doing it manually.  But what if you are an MSP and need to do this for an entire office or multiple companies? Now you need to be able to target entire departments, divisions, or companies, and doing it one at a time isn't going to cut it.

Using the same steps found in Fix # 1 above, we'll take this further by bringing our script into our RMM and targeting multiple computers simultaneously. 

  1. Copy in the solution from fix # 1 or fix # 2 depending on what version of Powershell you know is deployed within the environment you're targeting. 
  2. Paste the script into your favorite script editor and save it with a ".ps1" extension.
  3. Login to your RMM, in this case, it's N-able N-sight.
  4. Go to Settings, Script Manager
    n-able n-sight script manager
  5. Click New to create a new script.
    n-able n-sight script manager new script
  6.  Give your script a name, and description, leave the Default Timeout at its default value, and select the Automated Task and Windows checkboxes. 
  7. Upload the script you saved in step 2 by clicking the browse button.
  8. Click Save.
  9. Assign the script as a task at the Client or Site level to target multiple computers, or assign the task to individual machines. 

Summary

The beauty of this solution is that it's a two-liner PowerShell Script. Technically, I could've rewritten it to be a one-liner, but this way is clean and obvious what the script is doing.

Byron Zepeda

Byron Zepeda is a Senior Systems Engineer in Orange County, California, working with VMware vSphere, Citrix Virtual Apps, backups, and storage. As cloud technologies and automation become first-class citizens within IT organizations, he desires to share everything he learns and pass it on to others.