The Windows Management Instrumentation (WMI) interface is a management technology that has been positioned by Microsoft as the future standard for managing Windows platforms from Windows 2000 onwards. WMI was originally introduced in Windows NT 4.0 as part of service pack 4. Subsequently, it has been included as part of Windows 2000, XP and now Windows 2003 Server. Each new operating system release has added to the WMI functionality. The good news for Storage Managers is that WMI provides access to information on storage devices on all of your Windows servers. Better still, WMI can be easily scripted and integrated into web pages. In this, the first of two articles, we will look at the basics of WMI and develop scripts that allow us to monitor our environment for free. Our examples use VBScript, however it is possible to develop in any language capable of supporting COM automation. Why WMI?
WMI centralises the management of Windows servers and workstations into a common object-based infrastructure. By standardising functionality, additional management functions can be introduced into the WMI framework with great simplicity. As new functionality is introduced into later releases of the Windows operating system, providers are implemented to manage the new functions. Providers act as the interface between a computer resource (such as a disk drive or partition) and other WMI components handling the interaction with resources, to ensure that a standard interface is available through WMI. Windows Management Instrumentation isn't just for storage; it allows you to monitor and manage almost every aspect of your computer setup. You can find a list of the standard providers at: New providers have been introduced with Windows 2003 Server. For example, the Shadow Copy Provider is new with this operating system. So, let's get coding and see what we can do. Below is a script to display basic information on your local PC. Copy the data into a file with the extension *.vbs.
strComputer = "."
strOutput = ""

Set wbemConnection = GetObject("winmgmts:\\" & strComputer) Set wbmObject = wbemConnection.InstancesOf("Win32_DiskDrive")
strOutput = "Physical disks on " & strcomputer & vbCrLf For Each wbemObject In wbmObject stroutput = stroutput & "Physical Drive: " & wbemobject.Name & " - " & int(wbemObject.size/1048576) & "MB" & vbCrLf Next
strOutput = strOutput & "Partitions on " & strcomputer & vbcrlf
Set wbmObject = wbemConnection.InstancesOf("Win32_DiskPartition")
For Each wbemObject In wbmObject strOutput = strOutput & "Partition: " & wbemobject.Name & " - " & int(wbemObject.size/1048576) & "MB" & vbcrlf Next
wscript.echo stroutput
You should be able to then click on the script and see details of the physical hard disks and partitions on your local machine. See the picture on the right for a sample of the output. A word of warning here about security; as an administrator you will have access to run this script. If you do not have administrative rights, you should be able to execute the script as it simply reads configuration data. If not, you will need to speak to your System Administrator to request the appropriate rights. On a Windows 2000 machine or higher, enter the command wmimgmt.msc from a command prompt and right-click the "WMI Control" option. From there you can view security settings with the "Security" tab. Line-by-line
So how does this work? Well, line 3 of the code connects to the WMI service. The local computer is displayed as ".", but you can specify any remote computer to which you have access. Line 4 requests details on all objects of the class type "Win32_DiskDrive" on this machine. Lines 6 to 8 loop through each of the returned objects (each one representing a physical disk) and displays 2 properties, the "Name" and "Size". We then repeat this process, this time using the class "Win32_DiskPartition". As you can see, from a simple piece of code we can easily determine disk information on any computer we can access. The command standards in the format of the class objects makes it easier to re-use our existing code. There are dozens of classes that provide information on your computer and are logically grouped into namespaces. The classes used in this article are part of the root\CIMV2 namespace. Others include root\directory\ldap, which maps out Active Directory information and root\default, which provides access to the registry. A great way to see all of the available classes and their properties is to download the "WMI Object Browser", part of WMI Tools. You can find the download at: Once installed, open up "WMI Object Browser" from the menu. Accept the default namespace of root\CIMV2 and click "OK" to log in as your current logged in user. You can then expand the left-hand frame and locate the disk information under "Win32_SystemDevices". The right-hand pane will display details on the object you choose. Browse around and see what information is available. In the next article, we will look further at WMI. We'll also look at putting the storage information to practical use on a webpage and at what values can be modified.