WMI - Physical Disks Properties
VBScript WMI Disk Properties
Most WMI scripts obtain information that is available by launching various GUIs. In the case of disks, we could launch the Disk Administrator and observe the partition information in the window. However, the great advantage of script is that we can filter the data, interrogate multiple machines, and output the results to screen or to a text file. Perhaps the most important part of scripting is, building in logic and taking action based on information received. For example, if Manufacturer Model = xyz then apply hotfix q123.
There are two types of WMI disk object:
Win32_DiskDrive - Physical Disk data. Based on the number of blocks, tracks or sectors. (Pure disk data. See more on this page.)
Win32_LogicalDisk - Partition size Disk Type and FreeSpace. See more here.
This page has an important extra scripting feature, how to output WMI information to a text file. Whilst my script explains how to write disk data to a file, you could adapt the method to many other WMI scripts.
Topics for WMI Disks (Win32_DiskDrive)
This WMI sample file is about displaying low level disk information. How big is the whole disk, not just the partitions? What are the block, sector and track sizes? Which SCSI Bus is attached to which physical disk? Who is the manufacturer? What signature did the operating system give the disk?
Prerequisites for your Physical Disk Information WMI Script
No prerequisites. Be careful with _ Underscores when you copy and paste.
Instructions for your Physical Disk Information WMI Script
Script to Interrogate Logical Disk
From a WMI Perspective
1) GetObject("") is the usual VBScript method for connecting to an object. Winmgmts is the host, which looks after the CIM schema and objects. In other examples, in place of winmgmts, you may find wscript, LDAP:// or WinNT://. If it would aid your understanding, you could type winmgmt /? at the command prompt.
All WMI scripts begin by
using winmgmts to access the root of the CIM library,
here is the command:
3) Set colProcess = objWMIService.ExecQuery _ is a standard WMI phrase to prepare for the WQL command: Select * from Win32_DiskDrive
From a VBScript Perspective
4) strComputer is a classic example of naming a VBScript variable. It is good practice to name variables after the object to which they refer, in this case the computer. The ".", dot or period means the current machine where the script is running. Therefore, it would be easy to change the "." for the name of a server on your network. The beauty of using variables is that you only need to set the value once, instead of hunting through the script for every reference to the computer that you wish to interrogate.
4) What makes scripting so powerful is the speed with which VBScript loops through an array of objects or properties, in this instance the loop is controlled by: For Each....In... Next.
5) It is also possible to output the process information not to the screen but to a text file. In Example 2, we will investigate how WMI calls VBScript to create a file and write the output to file.
Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft's operating systems. Fortunately, SolarWinds have created a Free WMI Monitor so that you can discover these gems of performance information, and thus improve your scripts.
Take the guess work out of which WMI counters to use when scripting the operating system, Active Directory or Exchange Server. Give this WMI monitor a try - it's free.
This script is truly a classic, a routine to apply to other WMI scripts where you need to write information to disk.
Let us suppose you want to know if a disk drive is healthy, and the size in MB. Furthermore, you want to know the manufacturer and which SCSI bus each disk is using.
WMI Tutorial Learning Points
1) The purpose of this extra script is to output information to a text file. Take the trouble to check the strDirectory and strFile variables.
2) Pay particular attention the section beginning strText = "Computer: " & objItem.SystemName. I was torn between adding many more properties, and making the script even longer. As the focus of this script is on the .WriteLine method, is settled for reducing this section. However you could profitably research properties such as : objItem.SCSITargetId from Example 1 above.
This page takes you through the second Win32 disk property, Win32_DiskDrive. These properties display physical attributes of the disk, for example, the Model, number of cylinders, and the SCSI configuration. The icing on the cake is the second example which outputs to a file.
If you like this page then please share it with your friends
See more VBScript WMI examples:
Windows Management Instrumentation (WMI) is most useful for PowerShell scripting.
SolarWinds have produced this Free WMI Monitor to take the guess work out of which WMI counters to use for applications like Microsoft Active Directory, SQL or Exchange Server.
Author: Guy Thomas Copyright © 1999-2017 Computer Performance LTD All rights reserved.
Please report a broken link, or an error to: