How to uninstall software using Package management in PowerShell

Written by Alex Marin · August 4th, 2023

We've all been there - you're trying to uninstall a piece of software, but it just doesn't seem to be as straightforward as you'd like. Perhaps the traditional uninstall process is proving to be a hassle, or maybe the software doesn't seem to want to leave your system, no matter how hard you try.

That's where PowerShell comes in.

In this article, we’ll show you three effective methods that leverage the power of PowerShell to manage and uninstall software packages with ease:

  • WMI Method
  • Package Provider
  • Uninstallation String

Let's get started!

Uninstalling Software with the WMI Method

Windows Management Instrumentation (WMI) designs the backbone of device and application management within a Windows environment (locally or via the network). VMI provides users with information about the local or remote systems.

One of its key components is the Win32_Product class that embodies products installed by Windows Installer.

Follow these steps to use the WMI Method:

1. Get a list of all installed applications by executing the following PowerShell command:

Get-WmiObject -Class Win32_Product | Select-Object -Property Name

After a few seconds, the command will come up with a list of most applications installed on your PC.

WMI Method PowerShell

2. From this list, identify the exact name of the application you wish to uninstall. It's crucial to match the name exactly as it appears in the PowerShell output.

3. To locate your application, modify your command as shown below, replacing "PowerShell Test Application" with the name of your application:

Get-WmiObject -Class Win32_Product | Where-Object{$_.Name -eq "PowerShell Test Application"}
WMI command PowerShell

4. Now that we have output for our command, let’s create a variable that maps to your chosen application. From there, initiate the uninstallation command as follows:

$MyApp = Get-WmiObject -Class Win32_Product | Where-Object{$_.Name -eq "PowerShell Test Application"}
$MyApp.Uninstall()

While effective, the WMI Method has its limitations:

  • It is resource consuming.
  • There are cases where the WMI Repository is corrupted.
  • Not all applications can be uninstalled by the WMI Method.

In case you're unable to find your specific application using the WMI Method, the Get-Package cmdlet comes to the rescue, which leads us to the second method.

Uninstalling Software with Package Provider

PowerShell provides a set of cmdlets in terms of PackageManagement. These cmdlets allow you to manipulate system packages, and they include:

With these cmdlets you can uninstall packages installed on the system through various package providers.

Here's how to uninstall software using the Package Provider method:

1. To get the list of package providers use the Get-PackageProvider cmdlet:

Get-PackageProvider command

These are the default providers on a vanilla Windows OS.

2. Packages installed with msi, msu, Programs or PowerShellGet can be uninstalled with the Uninstall-Package cmdlet. You can add more providers by using the Install-PackageProvider cmdlet.

3. Similar to the WMI method, search for your package using the following command:

Get-Package -Name 'PowerShell Test Application' | ft -AutoSize
Get-PackageProvider command 2

Once you find the package you get additional details of that particular package, such as version, source path and the provider name.

4. To uninstall a package you can either:

- pipeline the Uninstall-Package cmdlet.

Get-Package -Name 'PowerShell Test Application' | Uninstall-Package

- or directly run the cmdlet by providing the package name.

Uninstall-Package -Name 'PowerShell Test Application' -Force

Uninstalling Software with the Uninstall String

The Uninstallation String method is ideal for custom packages. If a package appears in the Control Panel's Add & Remove Programs, it creates an entry in the registry.

The registry stores entries for packages as follows:

- For 64bit packages:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

- For 32bit packages:

HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall

To uninstall a package using the Uninstallation String, locate the specific package entry and identify its uninstall string.

For example, if we look at the UXP WebView Support package, we can see that it has a custom uninstall string.

uninstall string for software uninstalling

Conclusion

We've journeyed through the comprehensive landscape of uninstalling software packages using PowerShell, navigating through three dynamic methods - the WMI Method, Package Provider, and Uninstallation String. Each of these approaches is designed to give you control, flexibility, and precision when managing software on your system.

Whether you're handling conventional applications or unique, custom packages, these PowerShell methods offer powerful solutions for your uninstallation needs. The key is understanding each method's advantages and limitations, and strategically applying them based on your specific circumstances.

We hope this guide helps you harness the potential of PowerShell Package Management, enabling you to manage your software environment with confidence and efficiency. Continue exploring, and keep enhancing your software management skills. Remember, in the realm of PowerShell, you're only limited by what you don't know. Happy uninstalling!

Want to master PowerShell for software uninstallation and more? Watch our webinar and master the art of efficient software deployment.Webinar: PowerShell Integration in Advanced Installer | Streamlining your Deployments

Written by
See author's page
Alex Marin

Application Packaging and SCCM Deployments specialist, solutions finder, Technical Writer at Advanced Installer.

Comments: