Group Policy WMI Filter to Check if Windows Feature is Installed

group-policywmi

The following returns true for servers without the Server GUI installed:

WMIC PATH Win32_OptionalFeature WHERE "Caption = 'Microsoft-Windows-Server-Gui-Shell-Package-DisplayName' AND InstallState = 2"

However, my attempt to translate this into a WMI filter…

SELECT * FROM Win32_OptionalFeature WHERE Caption = Microsoft-Windows-Server-Gui-Shell-Package-DisplayName AND InstallState = 2

…failed with:

A syntax error occurred trying to evaluate a query string.

…Which is fairly unhelpful.

What's the failure and why?

Best Answer

I solved this as I was writing the question, and thought I'd share. I deceived myself when banging out the WMIC command and didn't think about the requirement for quoted values in the rather strict WQL syntax used here:

SELECT * FROM Win32_OptionalFeature WHERE Caption = "Microsoft-Windows-Server-Gui-Shell-Package-DisplayName" AND InstallState = "2"

Boring solution, but there you have it. It drove me to drinking, so I thought I'd save someone else's future productivity time.

Don't let it stop you from drinking, though. That's plenty productive.

Related Topic