When you are working with deployments, whether it is SCCM, MDT, Altiris, LanDesk or whatever tool you are using, or you’re building a script which uses WMI queries, there’s always some actions you only want to perform on certain computers. In SCCM and MDT there’s builtin support for WMI queries. For instance, you want to apply a mass storage driver only to a computer that has that controller present.
To build these WMI Queries, in the past I always used the WMIC commandline tool. A very handy tool, but the syntax for this tool is a bit different then your average:
SELECT * FROM Win32_ComputerSystem WHERE model LIKE ‘%DC7900%’
In WMIC this query would be translated to:
WMIC PATH Win32_ComputerSystem WHERE “model LIKE ‘%DC7900%’
For this particular query it’s not that different, but what if you only want to get certain values?
SELECT Model FROM Win32_ComputerSystem WHERE model LIKE ‘%DC7900%’
Would be translated to:
WMIC PATH WIN32_ComputerSystem WHERE “model LIKE ‘%DC7900%’ GET model
As you see, it’s not really hard translating the commands, but there’s an even easier way to get your WMI Queries
Use the builtin Windows Management Instrumentation Tester: wbemtest.exe
Start>Run>wbemtest.exe
Click on connect and type the namespace you want to connect to: (Default for WMI is root\cimv2)
Now we have all sorts of buttons available… we can easily open and explore a class and see it’s methods and properties… we can create a query in the syntax of:
SELECT * FROM Win32_ComputerSystem
Happy exploring and testing with WMI
Comments
Leave a comment Trackback