How would you handle the following scenarios?
- You have a Wireless Configuration and Offline Files GPO but only want laptops to see it.
- You have a BIOS update but only want a particular manufacturer to grab it.
- You have hardware (ex: SmartBoards) and want the software to automatically install when the device is connected.
In the past, I’ve tried to solve these issues with security groups, shadow groups, and careful OU placement. All were a pain to manage until I learned how to use WMI! In this three part series, we are going to cover WMI basics, using it with Group Policy, and integrating it with SCCM.
What is WMI and Why Should I Care?
Honestly, I can never remember what WMI stands for. I am sure that it is something like Windows’ Magical Interface but I could be wrong. In technical terms, it provides a standard method to query and store data. It gives an you a common way to extract hardware and software information! Ever wondered where inventory programs (like SCCM or Spiceworks) get their data? They are using WMI! Accessing this information is super easy and can save you a ton of time! But first, we need to briefly cover some terms.
WMI is organized into classes. Think of a class as an organized folder. The class Win32_BIOS will contain everything related to the BIOS. Win32_Processor stores the processor information. You can see available classes by typing wmic /? in a command prompt.
Each class contains members (objects). For example, the BIOS class contains a member named SerialNumber. We’ve made use of this before when we inventoried our serial numbers into Active Directory. Remember this: Classes Come Before Members.
Finally, you interact with members by using verbs. The two most common verbs that you will use are get and set. Let’s look at a few quick examples that shows how powerful WMI can be.
WMI Queries that You Can Use Now!
WMIC is the command that you will use to do any quick WMI query. Though the syntax is a bit strange, it is easy to understand. For simplicity, launch an administrative command prompt and type WMIC. You should now see: wmic:root\cli
Type bios get and you will see a very long list of members and their values. If you scroll to the right, you will eventually find the SerialNumber member and its value.
You could make this list a lot easier to read by typing bios get /format:list. This would give you the above output in a more structured vertical format. But what if you wanted to just display the serial number of the computer? Easy! Type bios get serialnumber
How would you query for the computer’s model? I would logically think bios get model. If you try to execute that, you will receive an invalid query error. So if the model member doesn’t exist in the BIOS class, how can we find it? One easy way is to search this post for common and useful queries. You can also explore MSDN. With either link, you will find model under the computersystem class. Our query would then look like: computersystem get model
To query a remote machine, we could preface our command with the /node parameter. Here is an example: /node:RemotePC computersystem get model . In our next WMI post, we will cover WMI in Group Policy! Specifically, how to create filters to dynamically apply your GPOs! If you have any tips for working with WMI, favorite queries, or questions – please leave a comment below.
* Turns out I was wrong… WMI actually stands for Windows Management Instrumentation.
One thing to mention is that if your remote computer name has a dash in it, you must use quotes. So if I am trying to do a get model query on a remote computer named remote-pc, I will have to type, /node:”remote-pc” get model
Thanks Alan – I didn’t know that! Do y’all use dashes in your names a lot?
WMI explorer is a great GUI for working with WMI, it’s free and portable. 4sysops has a good article and download link here
http://4sysops.com/archives/free-wmi-explorer-browse-wmi-classes-and-execute-any-wmi-query/
Also there’s another useful article on 4sysops that helps with building your queries, there’s a program again by MS that helps you, link here
http://4sysops.com/archives/free-wmi-code-creator-generate-vbscript-c-and-vb-net-code-that-uses-wmi/
FYI Deployhappiness is a great site! I love the idea, great articles!!
Those are two good links! Just a slightly bias statement but 4sysops has a lot of great content!!