udlp
udlp

Reputation: 187

Why is WMIC giving me Invalid query when trying to uninstall?

I'm trying to uninstall regular programs via PowerShell, and everything I've tried to put in the name="program name" section, appears to fail.

I've followed this guide here on how to do it.

I've tried removing Google Chrome as my test example. It's not actually want I want to remove, just a test target that I can easily and quickly reinstall.

I did first test on another machine which had Google Chrome, but didn't show up in this list. It also had this error. But now I tested on my main machine, where Google Chrome does show up in the list.

PS C:\WINDOWS\system32> wmic product get name                                                                           Name
Microsoft Visual C++ 2010  x64 Redistributable - 10.0.40219
Microsoft Visual C++ 2010  x86 Redistributable - 10.0.40219
Microsoft Visual Studio 2010 Tools for Office Runtime (x64)
Google Chrome
Google Update Helper
Microsoft SQL Server 2008 Native Client

PS C:\WINDOWS\system32> wmic product where name="Google Chrome" call uninstall
ERROR:
Description = Invalid query

Some irrelevant product get name entries have been removed to keep the list short.

I expect WMIC to uninstall the program, but instead I get the error found above.

Upvotes: 3

Views: 8392

Answers (3)

js2010
js2010

Reputation: 27526

You can try the package commands too, only for msi installs, which is all wmic product would work with anyway, very slowly.

get-package *chrome* | uninstall-package -whatif

Or you just needed an extra set of quotes:

wmic product where 'name="Google Chrome"' call uninstall

Or for non-msi install (or if you're lucky "quietuninstallstring"):

get-package 'google chrome' | % { cmd /c $_.metadata['uninstallstring'] }

You may have to add some extra option like "/S" on the end.

Upvotes: 1

Eduardo Mendes
Eduardo Mendes

Reputation: 9

Try this

wmic product where "name like 'Google Chrome'" call uninstall

use '' on program name and "" on name

Upvotes: 0

Rich Moss
Rich Moss

Reputation: 2384

The WMIC command requires the filter within quotes: wmic product where "name='Google Chrome'"

Powershell also exposes the Get-WMIObject cmdlet (alias gwmi) that has cleaner syntax:

$chrome = gwmi win32_product -filter "name='Google Chrome'"
$chrome.Uninstall

Upvotes: 2

Related Questions