Gathering disk usage information via WMI

Continuing on our saga through the undocumented Virtual Server WMI interfaces, we now arrive at disk usage information.  Here is a sample script that will create a list of the currently running virtual machines, and display the amount of disk activity they have had since they were powered on.

Set vsWMIObj = GetObject(“winmgmts:\.rootvmvirtualserver”)
Set vms = vsWMIObj.ExecQuery(“SELECT * FROM VirtualMachine”,,48)
For Each vm in vms
    Wscript.Echo “==============================================”
    Wscript.Echo “Virtual machine: ” & vm.Name
    Wscript.Echo “MiB read from disk: ” & vm.DiskBytesRead / 1048576
    Wscript.Echo “MiB written to disk: ” & vm.DiskBytesWritten / 1048576

As you can see these disk counters usually report values in bytes.  It is important to note that these counters are also reset to zero every time the virtual machine is turned off.