$app = Get-WmiObject -Class Win32_Product | Where-Object {
$_.Name -match "Software Name"
}
$app.Uninstall()
Edit: Rob found another way to do it with the Filter parameter:
$app = Get-WmiObject -Class Win32_Product `
-Filter "Name = 'Software Name'"
Answer from Jeff Hillman on Stack Overflow$app = Get-WmiObject -Class Win32_Product | Where-Object {
$_.Name -match "Software Name"
}
$app.Uninstall()
Edit: Rob found another way to do it with the Filter parameter:
$app = Get-WmiObject -Class Win32_Product `
-Filter "Name = 'Software Name'"
EDIT: Over the years this answer has gotten quite a few upvotes. I would like to add some comments. I have not used PowerShell since, but I remember observing some issues:
- If there are more matches than 1 for the below script, it does not work and you must append the PowerShell filter that limits results to 1. I believe it's
-First 1but I'm not sure. Feel free to edit. - If the application is not installed by MSI it does not work. The reason it was written as below is because it modifies the MSI to uninstall without intervention, which is not always the default case when using the native uninstall string.
Using the WMI object takes forever. This is very fast if you just know the name of the program you want to uninstall.
$uninstall32 = gci "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" | foreach { gp $_.PSPath } | ? { $_ -match "SOFTWARE NAME" } | select UninstallString
$uninstall64 = gci "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" | foreach { gp $_.PSPath } | ? { $_ -match "SOFTWARE NAME" } | select UninstallString
if ($uninstall64) {
$uninstall64 = $uninstall64.UninstallString -Replace "msiexec.exe","" -Replace "/I","" -Replace "/X",""
$uninstall64 = $uninstall64.Trim()
Write "Uninstalling..."
start-process "msiexec.exe" -arg "/X $uninstall64 /qb" -Wait}
if ($uninstall32) {
$uninstall32 = $uninstall32.UninstallString -Replace "msiexec.exe","" -Replace "/I","" -Replace "/X",""
$uninstall32 = $uninstall32.Trim()
Write "Uninstalling..."
start-process "msiexec.exe" -arg "/X $uninstall32 /qb" -Wait}
Why is it so difficult to uninstall a program using PS?
How can I uninstall the Windows Powershell?
how to uninstall a program using CMD or Power Shell ?
Need PowerShell working script to uninstall software from Control Panel,Registry
Videos
Can someone explain the process of uninstalling a program that displays in the control panel. Or point me to some documentation I can read.
I can’t even figure out how to uninstall Notepad++. Uninstall-Package does nothing, Remove-WmiObject does nothing, Remove-package does nothing.
Idk what i’m missing here
Within PowerShell, this is very easy to do.
The below block of script will take a computer name, your username and password, connect to the remote computer and list all installed software by name:
$computerName = "SomeComputerName"
$yourAccount = Get-Credential
Invoke-Command -ComputerName $computerName -Credential $yourAccount -ScriptBlock {
Get-WmiObject Win32_Product | Select Name
}
When you have the name of the product you want to uninstall remotely - you can the perform an uninstall like this:
$computerName = "SomeComputerName"
$appName = "AppName"
$yourAccount = Get-Credential
Invoke-Command -ComputerName $computerName -Credential $yourAccount -ScriptBlock {
Get-WmiObject Win32_product | Where {$_.name -eq $appName} | ForEach {
$_.Uninstall()
}
}
In the above eaxmples - replace "SomeComputerName" with the name of the computer you wish to uninstall from.
You can also make the script prompt you for a computer name if you prefer with the following line:
$computerName = Read-Host "Enter Computer Name"
If you have multiple computers with the same piece of software that you want to uninstall - you can also define an array of computers to work with and do uninstalls from lots of machines:
$computerNames = @("SomeComputerName1", "SomeComputerName2", "SomeComputerName3")
$appName = "AppName"
$yourAccount = Get-Credential
ForEach ($computerName in $computerNames) {
Invoke-Command -ComputerName $computerName -Credential $yourAccount -ScriptBlock {
Get-WmiObject Win32_product | Where {$_.name -eq $appName} | ForEach {
$_.Uninstall()
}
}
}
If you create a file called "servers.txt" and place your list of servers in it you could also reference $computerNames as follows:
$computerNames = Get-Content "C:\some-directory\servers.txt"
$appName = "AppName"
$yourAccount = Get-Credential
ForEach ($computerName in $computerNames) {
Invoke-Command -ComputerName $computerName -Credential $yourAccount -ScriptBlock {
Get-WmiObject Win32_product | Where {$_.name -eq $appName} | ForEach {
$_.Uninstall()
}
}
}
I've used this approach many times in production environments and it seems to work for me. Always test this in a non-production environment before completing in a prod environment.
I need to use a script with either CMD or Power Shell to uninstall a program from a windows machine.
To be clear , I already know how to use the “wmic” & "Get-WmiObject -Class Win32_Product ", what I am looking for is how to remove the programs listed under Programs & Feature in control panel but doesn’t show up when using WMIC (Product Get Name) or (Get-WmiObject -Class Win32_Product) commands.
I can use these script easily:
1. CMD:
wmic
product get name
product where name=“program name” call uninstall
2. Power Shell:
$app = Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -match “Software Name” } >> $app.Uninstall()
Both scripts above helped me remove specific programs only, but the list I have under control panel still have lots of other applications that I am hoping to use similar script to remove them.
Any idea / suggestion is highly appreciated ?
If the application was installed by MSI, and if you know the GUID, you can use msiexec to uninstall the application. That is the most efficient way, provided that the prerequisites are true.
Win32_Product is very inefficient.
Scripting Blog [archived] – 13 Nov 11
Use PowerShell to Quickly Find Installed Software - Scripting Blog [archived]
Summary: Learn how to use Windows PowerShell to quickly find installed software on local and remote computers. Microsoft Scripting Guy Ed Wilson here. Guest Blogger Weekend concludes with Marc Carter. The Scripting Wife and I were lucky enough...
Scripting Blog [archived] – 14 Dec 11
Use PowerShell to Find and Uninstall Software - Scripting Blog [archived]
Summary: Learn how to use Windows PowerShell to get software installation locations, and to uninstall software from remote computers. Hey, Scripting Guy! We have a dumb application that we have to use at work. The company has released a new version...
You need two more quotes around the argumentlist. This will force a reboot as they are uninstalled in my test. You could probably avoid that with an additional switch though.
Edit: this should be the final one.
$program = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall | Get-ItemProperty | Where-Object {$_.DisplayName -match 'c\+\+ 2015-' } | Select-Object -Property DisplayName, Uninstallstring, QuietUninstallString
foreach($prog in $program){start-process cmd.exe -argumentlist "/c ""$($prog.quietUninstallString) /norestart""" -Wait}
Hi Experts,
I have to uninstall Microsoft Visual C++ 2019 X64 Additional Runtime - 14.29.30133 & Microsoft Visual C++ 2019 X86 Additional Runtime - 14.29.30133 software from my Control panel and Registry.
caa06090-a4f2-4a72-a496-f129b0aaa1ac-Control_panel.PNG745×163 50.5 KB
I have tried from the below powershell code, I am not getting any error. But Its not uninstalling. Not working.
Can someone provide me effective powershell script to uninstall it.
I am looking forward to hear from you.
$Myapp1 = Get-WmiObject -Class Win32_Product | Where-Object{$_.Name -eq "Microsoft Visual C++ 2019 X64 Additional Runtime - 14.29.30133"}
$Myapp1.Uninstall()
$Myapp2 = Get-WmiObject -Class Win32_Product | Where-Object{$_.Name -eq "Microsoft Visual C++ 2019 X86 Additional Runtime - 14.29.30133"}
$Myapp2.Uninstall()
You could use this PowerShell fragment :
$program = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall | Get-ItemProperty | Where-Object {$_.DisplayName -match "Part of App Name" } | Select-Object -Property DisplayName, Uninstallstring, QuietUninstallString
start-process cmd.exe -argumentlist "/c ""$($prog.quietUninstallString) /norestart""" -Wait
Where "Part of App Name" is enough to uniquely identify the product.
I was able to write a small PowerShell script for my specific need:
# Name of the software to check
$softwareName = "O365ProPlusRetail - de-de"
# Check if software is installed
$software = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object { $_.PSChildName -match $softwareName }
if ($software -ne $null) {
# Software is installed, uninstall it
& 'C:\Program Files\Common Files\Microsoft Shared\ClickToRun\OfficeClickToRun.exe' scenario=install scenariosubtype=uninstall sourcetype=None productstoremove=O365ProPlusRetail.16_de-de_x-none culture=de-de version.16=16.0 DisplayLevel=False forceappshutdown=true
Write-Host "$softwareName has been uninstalled."
}
else {
# Software is not installed
Write-Host "$softwareName is not installed."
}
it works for me but this is not a general solution.