Looking at VM Uptime through WMI

Another useful WMI counter that is exposed by Virtual Server is the virtual machine uptime (how long the virtual machine has been running since it was last started or rebooted).  This is reported in seconds, so I had to do some tweaking with mod and div to get it to display nicely, but:

Set vsWMIObj = GetObject(“winmgmts:\.rootvmvirtualserver”)
Set vms = vsWMIObj.ExecQuery(“SELECT * FROM VirtualMachine”,,48)
For Each vm in vms
    Wscript.Echo “Virtual machine: ‘” & vm.Name & _
   “‘   Uptime: ” & vm.Uptime 86400 & ” days, ” & _
   (vm.Uptime 3600) mod 24 & ” hours, ” & _
   (vm.Uptime 60) mod 60 & ” minutes, ” & _
   vm.Uptime mod 60 & ” seconds.”

Two comments to make, under Virtual Server WMI is only used for reporting statistical counters.  There is no way to change anything through WMI, just observe it.  The second comment is that you should be careful about your slashes :-).  In VBscript ‘/’ will give you a floating point number with appropriate decimal values while ” performs div and returns the value rounded down to the nearest integer.