Targeting Windows 7 with Group Policy: Why White Space Matters

This morning, I endeavored to do a simple thing with Group Policy: write a WMI filter that targeted Windows 7 clients. So, I double-checked the syntax required, and ran the following PowerShell command to get the right text:

get-wmiobject win32_operatingsystem | select caption

Simple enough. Here was my WMI query:

SELECT * FROM Win32_OperatingSystem WHERE Caption = “Microsoft Windows 7 Professional”

Result? “Filtering: Denied (WMI Filter)”

I can’t count the times I looked over the syntax, compared it with others online, checked the namespace, and ran gpresult. Finally, I came to a post on Technet: http://social.technet.microsoft.com/Forums/en/winserverGP/thread/0bca8962-cd35-48da-ace1-856b334a9d5c

The suggested answers just sent me through the same stuff I had already checked. Expecting the usual slew of “I’m having this problem too!” responses, I begrudgingly scrolled to the bottom. Surprisingly, I did not find the typical replies, but rather a response from the user “aac396”:

‘I just ran into the same problem and found the answer.  The WMI result of caption has a space at the end of Microsoft Windows 7 Enterprise.  My query was “Microsoft Windows 7 Enterprise” and it never worked.  I added a space at the end of “Microsoft Windows 7 Enterprise ” and it’s fine now.’

Note the trailing space after “Enterprise.” No one had marked this response as helpful, so I doubted it would actually work for me. Maybe it was one of those one-in-a-million solutions that everyone else raises their eyebrows at. But, quite to my satisfaction, the following query worked:

SELECT * FROM Win32_OperatingSystem WHERE Caption = “Microsoft Windows 7 Professional ”

I had to laugh. Suddenly, the other suggestion of searching “Microsoft Windows 7%” made perfect sense. And it is something that really would not stand out in a PowerShell window. So, when repeatedly traumatizing your head against a blunt object with WMI filtering, check for any white spaces Microsoft may have included as a bonus.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s