Uninstall any application in a jiffy using PowerShell and Configuration Manager

Introduction

I was recently tasked with the complete removal of Google Chrome from an environment. Google Chrome in question was installed via the default installer from Google, but also via a few custom repackaged installers, so I had multiple product IDs to consider.

Instead of manually looking for each product ID and use that with separate uninstallations, I figured to create some PowerShell codeΒ to do that for me automatically and on the fly.

This can be used to uninstall any application registered with the Windows installer, installed either as a .MSI or a select .EXE compiler.

PowerShell

The script can be found on my GitHub repository: PowerShell/Uninstall-Application.ps1 at master Β· imabdk/PowerShell (github.com)

The script accepts and requires the parameter -displayName. Use the name of the application, as it’s presented to you in Programs and Features.

The script queries registry for the installed application and looks for the attached UninstallString.

Configuration Manager

Package and Program

Use the script in a regular package with a program running the script:

  • %SystemRoot%\sysnative\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -WindowStyle Hidden -File .\Uninstall-Application.ps1 -displayName “Google Chrome”

NOTE: Notice that I call PowerShell from the sysnative library to force PowerShell into a 64-bit process. This is required, as a package in ConfigMgr runs as a 32-bit process. Otherwise the script cannot read the relevant parts of the registry.

For your convenience, a few snippet of the program. The script assumes the applications are installed for the local machine, hence it requires to run with administrative permissions.

Enjoy πŸ™‚

**Update 19-12-2023**

I added support to pass multiple values to the script parameter -displayName in order to uninstall multiple applications in one go πŸ™‚

13 thoughts on “Uninstall any application in a jiffy using PowerShell and Configuration Manager”

  1. Nice blogpost!

    I’ve got the same that Google installed other apps.

    What is best practice to remove Google Chrome (and all unwanted programs) and then direct install new Google Chrome without the unwanted programs. This script and rely on Intune for the new install or install Google Chrome directly in your script?

    Reply
    • I would split it up in 2 separate deployments. Remove all the apps you don’t want via my script or whatever you prefer, and then create an enterprise ready installer of Google Chrome :_)

      Reply
    • Absolutely. Intune has the same authority as ConfigMgr in this regard. Intune however doesn’t support passing parameters to the script in it’s script feature. Instead you just define what the -displayName parameter inside the script before uploading to Intune.

      Reply
      • The program (in this case 7-zip) is found:

        Installed applications matching ‘7-zip’ found in HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
        Script is done running

        but then it is not uninstalled

        Reply
        • Are you using the 2.0 version of the script? I updated it this morning. Also, paste all of the output from the script. There’s more details being logged, which can give you clues about why.

          Reply
          • I tried again now with the updated script but still have the same “problem”; I will try to investigate as you suggested

  2. Remove-MSIApplications -Name ‘Your Application Name’ from PSAppDeployToolkit is a better alternative.
    Why reinvent the wheel when PSAppDeployToolkit is ten years in development and battled hardened on millions of computers.
    And it’s free with community support from thousands of users.

    Reply
    • Sure and that’s great. I don’t force anything on people. I prefer to create something myself and if anybody can use that as well, then I’m happy. If you want to use PSADT, then I’m happy too. Merry Christmas. πŸ™‚

      Reply
  3. Hello,

    Thanks for sharing a nice script, I have downloaded it and will test it soon.

    My question is this: The application I am trying to remove from our domain is CutePDF Writer, installed by .exe. The problem is that this app. does not even show up in either of the standard two registry locations for uninstall script, 64 or WOW6432Node.

    Will this script pick up this application or any other if they are not even listed in either registry hive?

    Thanks!

    Reply
    • I’m afraid it won’t. The script is depending on the application being registered within the registry. πŸ™‚

      Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.