The VBScript Network and Systems Administrator's Cafe

Feb 20 2008   7:47AM GMT

Using Windows Management Interface (WMI) to Make Your Life Easy.

Jerry Lees Jerry Lees Profile: Jerry Lees


In this blog entry I want to setup the next few blog entries that will deal with a technology that is quite possibly one of the most powerful tools in a Network Administrators tool chest… the Windows Management Interface or WMI.

WMI is a powerful tool when combined with scripting, you can use it to gather a vast array of information very quickly from a system or a number of systems. It is pretty easy to use once you have a basic script to setup the objects to make the calls, you know the Win32 class you want to call to query the information, and when you know what properties and/or methods to use. (no, this isn’t exactly the same as the C win32 classes or the windows foundation classes)

Think of Methods as subroutines or functions to accomplish a specific task, like starting a service. Think of properties as variables that you can check the value of to do something.

WMI can be used to also make configuration changes as well– imagine the company you work for just bought another company and you need to add their DNS suffix to all your servers and client machine’s TCP/IP properties’ search order and there are several hundred machines. Would you touch them all over a weekend? No! Be Lazy, and gain the respect of your new bosses if you were on the other side of the buy out! 😉 Do it with WMI in under an hour while you sip a Mountain Dew.

Another possibility is, say you have a Production SQL server that needs a RAM upgrade but no one can recall exactly what the memory configuration is that makes up the 4Gb of RAM in it. Was it 4 1Gb sticks, or 8 512Mb sticks? Were there any free slots? Guess you’ll have to come in during the 3am maintenance window (for 5 minutes) to figure it out so you can order the right parts. No! Be Lazy, WMI can tell you EXACTLY what the memory configuration is to make up the total and how many slots are available/free!

 Here is a good introduction article on WMI for you to look over and read. After reading that article you might want to poke around the Microsoft Documentation for the Win32 Classes for WMI. Be sure and bookmark the win32 classes page– it will be invaluable to you.

To make a call from a script to WMI you have to “create the WMI object” you want to work with. This is done in just a few lines of code. Then you actually create the object with a SQL like call like any of the following (These are examples to get the juices flowing… I haven’t tested them):

  • Select * from Win32_PrinterDriver
  • Select Caption from Win32_BIOS where Releasedate < ’07/01/07′
  • Select * from Win32_Service where Started = True

After that you treat the object you created just like any other object, you just have to know what the properties and methods are, here is a highlight of some of the properties and methods for Win32_Service.

The properties are:


Example Methods are:


There are others, but I think you’ll get the general idea. Next time, I’ll be sharing a quick script to display Device Drivers that are in use by printers on a server or workstation. Until then… Be Lazy!

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: