search
top

How To Uninstall Programs Using PowerShell

PowerShell is just one of those tools for Windows that continues to get better and better in uses you find on a day to day basis. One such tedious task is uninstalling programs. Wouldn’t it be awesome to create a script to automate this for many or even one system? In this post we will cover how to get a list of installed programs and how to remove one at a time or many at once.

Using PowerShell to get a list of applications installed.

Open a PowerShell session and type the following command. This can take awhile to get back results.

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

psprgrem1

 

Now that we have a list of the programs installed find the one you want to remove and move on to the next step.

Individually uninstalling programs.

At this point you can use your favorite editor and create  a script or use the PowerShell ISE to test out your command. In this example we will create a variable called app in define the WMI call to run the same command we did earlier to get the list but use Where-Object does a match to the exact program to uninstall. Then execute $app.Uninstall to remove it. In this example shows uninstalling  HP ProLiant Health Monitor Service (X64).

$app = Get-WmiObject -Class Win32_Product | Where-Object {
$_.Name -match “HP ProLiant Health Monitor Service (X64)”
}

$app.Uninstall()

Removing many programs at once with the foreach loop.

In this next example we will create a new variable called programs that will contain a list of programs to install then taking the same code as used above we will create a foreach loop that will go through each of the programs defined in the programs variable until all is removed.
$programs = @(“program1”, “program2”, “program3”)
foreach($program in $programs){
$app = Get-WmiObject -Class Win32_Product | Where-Object {
$_.Name -match “$program”
}
$app.Uninstall()
}

These are just a few examples of using PowerShell to uninstall programs from your system(s).

17 Responses to “How To Uninstall Programs Using PowerShell”

  1. Serge Meeuwsen says:

    That’s great but it doesn’t actually show you all the programs that are installed.
    The list you get when you do:
    Get-WmiObject -Class Win32_Product | Select-Object -Property Name

    lacks quite a bit when compared to the “uninstall a program” list in Control Panel.

    If you want everything, you’ll need something like this:

    If(!([Diagnostics.Process]::GetCurrentProcess(). Path -match ‘\\syswow64\\’)) {
    $unistallPath = “\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\”
    $unistallWow6432Path = “\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\”
    @( if (Test-Path “HKLM:$unistallWow6432Path” ) { Get-ChildItem “HKLM:$unistallWow6432Path”} if (Test-Path “HKLM:$unistallPath” ) { Get-ChildItem “HKLM:$unistallPath” } if (Test-Path “HKCU:$unistallWow6432Path”) { Get-ChildItem “HKCU:$unistallWow6432Path”} if (Test-Path “HKCU:$unistallPath” ) { Get-ChildItem “HKCU:$unistallPath” } ) | ForEach-Object { Get-ItemProperty $_.PSPath } | Where-Object { $_.DisplayName -and !$_.SystemComponent -and !$_.ReleaseType -and !$_.ParentKeyName -and ($_.UninstallString -or $_.NoRemove) } | Sort-Object DisplayName | Select-Object DisplayName
    }
    else {
    “You are running 32-bit Powershell on 64-bit system. Please run 64-bit Powershell instead.” | Write-Host -ForegroundColor Red
    }

    • newlife007 says:

      You are correct it lacks detail like uninstall a program but the post was just a quick way to uninstall a program, yours adds that detail and I appreciate the feedback!

    • Mystery says:

      This code is quite better, how can you add uninstall program to variable and call .uninstall?

      • newlife007 says:

        .Uninstall is a method of the Win32_Product class. In the example I am creating a variable called $app in which I define it using Win32_Product class which allows me to use the methods available of which .uninstall is one of them.

        • Hazz says:

          Sorry for the old post hit.
          I tried your script looking for a way to uninstall “Dell System Detect” to build a login script to remote machines. Your code did not show the “Dell System Detect” program. Serge’s code did populate it in the list. So how do you uninstall something that doesn’t show as being a win32_product class object? I did try the uninstall script listed below by Brian but it did not remove the program. I’m assuming because it isn’t a WmiObject.
          Sorry I am very new to PS. Like this is my first real attempt due to trying to fix an issue I created. 🙂

        • Guillaume Lachance says:

          quick!? I can take 30-40 mins to call Win32_Product. It can also fail. It’s really an absolutely terrible way of enumerating products.

          For posterity, from the docs:

          [code]
          Win32_Product is not query optimized. Queries such as “select * from Win32_Product where (name like ‘Sniffer%’)” require WMI to use the MSI provider to enumerate all of the installed products and then parse the full list sequentially to handle the where clause. This process also initiates a consistency check of packages installed, verifying and repairing the install. With an account with only user privileges, as the user account may not have access to quite a few locations, may cause delay in application launch and an event 11708 stating an installation failure. For more information, see KB Article 794524.
          [/code]

          • newlife007 says:

            This post was written long ago and PowerShell has changed much since then and this is really not the best way to uninstall but at the time of writing it worked for what I was looking for. There are many different ways to do tasks, some better than others.

  2. Marcin says:

    foreach($program in $programs){
    $app = Get-WmiObject -Class Win32_Product | Where-Object {
    $_.Name -match “$program”
    }
    $app.Uninstall()
    }

    This will revoke three uninstall processes for each program at the same time. Is there a way to prevent that? How to wait for uninstall to finish before proceed to next app?

  3. Don says:

    Hello,

    How to uninstall a program remotely that is not a WmiObject.

    I have installed TightVNC 2.0.4.EXE on a client machine. When I use the Get-WmiObject the TightVNC 2.0.4 is not listed and i can not uninstall this remotely.

    It is listed in the add/remove programs of the control panel as TightVNC 2.0.4

    So how can I uninstall this programm remotely using powershell..??

    Thanks..

  4. Umm says:

    Nice article; however, I thought the continuing advice was to avoid the Win32_Product WMI object for these kind of queries? See https://blogs.technet.microsoft.com/heyscriptingguy/2013/11/15/use-powershell-to-find-installed-software/.

    Has this changed or is there some other reason it is safe to use this object in your scenario?

    Thanks

  5. Brian says:

    The script works but an error is generated if null (one of the programs is not installed). I cleaned up the script to uninstall if not null.

    # Remove Lync and Skype if installed.
    $programs = @(“Skype for Business Basic 2016 – en-us”, “Microsoft Lync 2010”)
    foreach($program in $programs){
    $app = Get-WmiObject -Class Win32_Product | Where-Object {
    $_.Name -match “$program”
    }
    if ($app -ne $Null) {

    $app.Uninstall()
    }
    }

  6. shai says:

    Thanks!

  7. DJ says:

    Everytime i use this i get the same error,
    Im not quite sure where i’m messing up.

    You cannot call a method on a null-valued expression.
    At line:5 char:1
    + $app.Uninstall()
    + ~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

  8. Raju says:

    How can uninstall and again reinstall symantec compliance suite

  9. Ed Aragon says:

    Thank you. For a newbie like me. This is very helpful.

  10. BobTheBuilder says:

    Does anyone know how to install a .exe file silently using powershell

    • newlife007 says:

      As far as I know and have seen with .exe if it does not have the feature compiled in it you cannot make it install silently. You can install but it will popup a window.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

top