How to Uninstall a Program with PowerShell?

If you are an IT administrator, you might get requirements to uninstall software from single and multiple computers. This is possible using a PowerShell script. In this tutorial, I will explain how to uninstall a program using PowerShell.

You can uninstall programs through the control panel, but it is time-consuming, especially when dealing with multiple computers. So, we can use Microsoft PowerShell to uninstall programs.

Note: You need to have administrative privileges for this kind of operation.

Uninstall Programs Using PowerShell

Follow the steps below to uninstall programs using Microsoft PowerShell.

Step 1: Open PowerShell with Administrative Privileges

To begin, you need to open PowerShell with administrative rights. Follow these steps:

  1. Press Windows + X and select Windows PowerShell (Admin).
  2. If prompted by User Account Control (UAC), click Yes.

Step 2: List Installed Programs

First, you need to get a list of all installed programs on your computer. You can use the Get-WmiObject cmdlet to retrieve this information. Run the following command:

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

This command will display a list of all installed programs. Note the exact name of the program you want to uninstall. The exact output can be seen in the screenshot below.

Uninstall Programs Using PowerShell

Step 3: Uninstall the Program

Once you have identified the program you want to uninstall, use the Uninstall method of the Win32_Product class. Here’s an example of how to uninstall a program named “Adobe Acrobat Reader DC”:

$program = Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -eq "Adobe Acrobat Reader DC" }
$program.Uninstall()

This script searches for “Adobe Acrobat Reader DC” and uninstalls it.

Example: Uninstalling Mozilla Firefox

Let’s go through a real-world example of uninstalling Mozilla Firefox using PowerShell.

  • List Installed Programs:
Get-WmiObject -Class Win32_Product | Select-Object -Property Name
  • Identify Mozilla Firefox: Look for “Mozilla Firefox” in the list of installed programs.
  • Uninstall Mozilla Firefox:
$firefox = Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -eq "Mozilla Firefox" } $firefox.Uninstall()

Step 4: Verify Uninstallation

After running the uninstall script, it’s a good practice to verify that the program has been successfully removed. You can do this by re-running the command to list installed programs:

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

Ensure that the program no longer appears in the list.

Uninstall a Program with PowerShell

Uninstall Programs Using Uninstall-Package Cmdlet

For more advanced scenarios, you can use the Uninstall-Package cmdlet, which is part of the PackageManagement module. This method is particularly useful when dealing with packages installed via package managers like Chocolatey.

  1. List Installed Packages: Get-Package
  2. Uninstall a Package: Uninstall-Package -Name "MozillaFirefox"

Create a Reusable Script

If you frequently need to uninstall specific programs, you can create a reusable PowerShell script. Here’s an example PowerShell script to uninstall multiple programs:

$programs = @("Mozilla Firefox", "Adobe Acrobat Reader DC")

foreach ($program in $programs) {
    $app = Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -eq $program }
    if ($app) {
        $app.Uninstall()
        Write-Output "$program has been uninstalled."
    } else {
        Write-Output "$program is not installed."
    }
}

Save this script as UninstallPrograms.ps1 and run it with administrative privileges.

Read How to Set Default Browser Using PowerShell?

Troubleshooting Common Issues

Now, let me explain you something important. Here, I will explain how to troubleshoot some of the common issues.

Program Not Found

If PowerShell cannot find the program, ensure that you have the exact name as listed by Get-WmiObject. The names must match exactly.

Insufficient Privileges

Ensure you are running PowerShell as an administrator. Without administrative privileges, the uninstallation will fail. And this error might come.

Dependencies and Errors

Some programs may have dependencies or require specific conditions to be uninstalled. Check the program’s documentation for any special uninstallation instructions.

Conclusion

In this tutorial, I explained how to uninstall programs using PowerShell with real examples. We also learned how to write a script to reuse over time.

You may also like:

100 PowerShell cmdlets download free

100 POWERSHELL CMDLETS E-BOOK

FREE Download an eBook that contains 100 PowerShell cmdlets with complete script and examples.