SQLTeam.com | Weblogs | Forums

Need help with WMI filter query


#1

I need to create a WMI filter based on the following two queries. I know there is a JOIN or UNION syntax I need to use here, but not sure exactly how to do it. Any help is greatly appreciated. So, looking to query on all devices with IE 11 and some flavor of Java 6 in one query.

QUERY1
Select * from CIM_Datafile Where Name = 'C:\Program Files\Internet Explorer\iexplore.exe' AND version LIKE "11%"

QUERY2
SELECT * FROM Win32_Product WHERE name LIKE "Java 6%"


#2

Show us some sample output from both and what you want the result set to look like. Just sample data, doesn't have to be your actual data.


#3

There's no output, it's a WMI filter for group policy. Those two queries work, I just need to them be written as one query.


#4

If the queries work, they produce an output. I couldn't, personally, get them to run as queries. If we knew the structure of the outputs it might be possible to see how they relate to each other, perhaps with a JOIN, or if they might be combined together, perhaps with a UNION. In the absence of the result sets, it's nigh impossible to know how to operate on them. Can you shed a little light?


#5

This is a query that filters devices for group policy, I'm not a DBA, but a GPO admin. So, for the sake of argument, let's ignore output, this is a filter. So, if you were going to combine those two statements, each grabbing from a different WMI table, what would be the syntax to combine those two statements?


#6

We can't say how to combine them because we haven't seen sample data for those 2 queries. We don't even know what columns they return. Because of this, we can't answer your question.

You'll need to provide sample data that those 2 queries return and then show us what you would like the two queries to return when combined.


#7

Firstly, WMI is not SQL Server.

I have no experience on that area. But a quick search shows that

https://msdn.microsoft.com/en-us/library/windows/desktop/aa394606(v=vs.85).aspx

And from that link, i don't see any JOIN or UNION keyword listed, so I guess you have to "combine" the output of both the query yourself.


#8

Hah... yeah... excellent link (seriously). WQL is actually a subset of ANSI SQL and doesn't have such things as UNION, etc. Still, it's incredibly useful. I made my Enterprise-Wide Morning Disk Report using WMI/WQL although I also used it as an {ugh!} PowerShell example.


#9

To perform these processes, it is required that you must be a member of the Domain Administrators group, or must be a delegated permissions to modify.
First, create the WMI filter and configure it to look for a specified version (or versions) of the Windows operating system.
Know more how to create WMI Filters @ https://technet.microsoft.com/en-us/library/jj899801.aspx


#10

I figured it out. Apparently you can just add each query as a separate query in the same filter and it sees those as "joined" if you will or an "AND". Just never had to pull in from two different classes before into the same filter. Thanks for all the advice. Yeah, WQL if very similar to SQL. We have used some powershell before as well, but geez, that is certainly not an intuitive scripting language.


#11

Very cool feedback. Thanks for that. Hadn't though of doing such a thing before but that's good to know.