You can try to use the Win32_Product CIM class’s Uninstall method.
$Prod = Get-WMIObject -Classname Win32_Product | Where-Object Name -Match 'PrintForm 2018 CS'
$Prod.UnInstall()
or
Get-CimInstance -Classname WIn32_Product | Where-Object Name -Match 'PrintForm 2018 CS' |
Invoke-CimMethod -MethodName UnInstall
if you want to get fancier, you can use the -Filter parameter when getting the WMI object and filtering at source - left as an exercise for the reader.
Answer from DoctorDNS on community.spiceworks.comYou can try to use the Win32_Product CIM class’s Uninstall method.
$Prod = Get-WMIObject -Classname Win32_Product | Where-Object Name -Match 'PrintForm 2018 CS'
$Prod.UnInstall()
or
Get-CimInstance -Classname WIn32_Product | Where-Object Name -Match 'PrintForm 2018 CS' |
Invoke-CimMethod -MethodName UnInstall
if you want to get fancier, you can use the -Filter parameter when getting the WMI object and filtering at source - left as an exercise for the reader.
Is there a way I can achive with POWERSHELL what I do with the command batch? Obviously I can only uninstall the product using this command (but I use a powershell script to query other things before)
WMIC product where name=“PrintForm 2018 CS” call uninstall
Command line solution for removing apps not listed in wmic product, installed in user's appdata
WMIC software uninstall file in use prompt bypass
Using WMIC in a batch file to uninstall a program - Stack Overflow
Using WMI uninstall commands with variables?
Videos
Every program that properly installs itself according to Microsoft's guidelines makes a registry entry in HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall. Usually, the key for the program will be its GUID, or else the name of the program. Within that key will be an entry called UninstallString. This contains the command to execute to uninstall the program.
If you already know ahead of time what you will be uninstalling, it should be easy enough to just put that in your batch file. It gets tricky when you try to automate that process though. You can use the reg command to get data from the registry, but it returns a lot of text around the actual value of a given key, making it hard to use. You may want to experiment with using VBscript or PowerShell, as they have better options for getting data from the registry into a variable.
You can invoke the correct uninstaller without knowing the GUID, etc. by using WMIC.
To see a list of the names of the programs as known internally by Windows:
wmic product get name
Look for your product name. It probably matches the one listed in the "Programs and Features" control panel, but not always.
Then you can use
wmic product where name="_my_product_name" call uninstall
to perform the uninstall, which AFAIK should be silent (it has been in my experience, but try it before you bet the farm on that. Silence may depend on how your installer/uninstaller was built).
See here for more:
- WMIC: the best command line tool you've never used (overview of WMIC with lots of cool commands described)
- Windows: Uninstall an Application from the Command Line (the specific recipe)
There's also reference documentation for WMIC on microsoft.com.
I can utilize SCCM to run commands I need to under the user's context, but some software doesn't show using wmic product, and cannot be uninstalled using powershell uninstall package.
However, these programs still show for the user in add/remove programs and uninstall from there when performed manually. I would just tell them to do this, but we cannot rely on user compliance and must ensure it gets done ourselves.
I imagine you could utilize some sort of registry query that tells you where to find an uninstaller, but I imagine that isn't even assured, not to mention some uninstallers or setup files requiring switches to function properly. I could also just delete the apps from appdata, but that would leave taskbar icons etc behind.
Even if it's a 3rd party program that has a command line interface (portable would be better), it would be a potential solution.
Why not run the script at logoff or during a reboot for patches.
Hi, I’m trying to uninstall Adobe products on a select group of user’s PCs using this script.
“wmic product where “name like ‘Adobe Acrobat Reader%’” call uninstall /nointeractive”
The script works, I’ve tried it on a few test PCs. However, while uninstalling, a box pops up that says “file in use” and lists open adobe files or Outlook. We’re trying to do this completely silently. Is there a way I can script out to “ignore” automatically, or execute completely without user intervention? Thanks in advance
After some excruciating trial and error, we found the below script that did the trick! Simple and elegant and quick. No need to install the NuGet module on systems. Copy and pasted this into our task sequence step in SCCM/MECM, and good to go! If you want to use for your own purposes, just replace 'TeamViewer Host" in the script with the name of the program you want to get rid of. This only works with MSI installed programs, not EXEs.
$uninstall32 = gci "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" | foreach { gp $_.PSPath } | ? { $_ -match "TeamViewer Host" } | select UninstallString
$uninstall64 = gci "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" | foreach { gp $_.PSPath } | ? { $_ -match "TeamViewer Host" } | 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 /qn" -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 /qn" -Wait}
You should never use Win32_Product, it has unintended side-effects that can/will cause issues. Serach the web for articles describing it as "Evil" for full details.
See https://home.memftw.com/uninstall-software-en-masse/ for a possible path.
wmic product where "name like 'SoftwareToUninstall%%'" call uninstall /nointeractive
I asked a few years ago. There's CimInstance. This line (I haven't tested this much myself, if you run this as is.)....
Get-CimInstance -Class Win32_Product -Filter "Name='software'" | Invoke-CimMethod -MethodName Uninstall
So great. Just user CimInstance in powershell and get a similar result.... But querying Win32_Product can have issues with doing an integrity check on all software and reinstalling everything. Something like that.
I was looking at pulling uninstall lines from here.
HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall HKLM: \Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall
It depends how software was installed for what works to uninstall it. I found the wmic line useful and still used it after wmic was deprecated. I haven't found anything that's a nice simple one-liner like it, although, yes, it's not perfect.