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
WMIC software uninstall file in use prompt bypass
Command line solution for removing apps not listed in wmic product, installed in user's appdata
WMIC Command For Uninstall An Application Or Software
Using WMIC in a batch file to uninstall a program - Stack Overflow
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.
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
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.
I think WMIC commands can be run from a single line which should make it easier to add to a batch file. And by adding /nointeractive then it should disable prompting as well. Try something like this:
wmic product where name="software" call uninstall /nointeractive
Although that may be possible for certain specific installations it's not possible to do so for all installations. As Zypher has already indicated, it will depend a great deal on the installation system used. It will also depend on whether that system allows for a "quiet" uninstall.
I really can't image a "perfect method using WMI" but congratulations if you've found one. On the other hand, you've also discovered one of the things that will get in the way of achieving your goal.