Ben Armstrong comes to the rescue again with another coding post on his blog site. This time, Ben shows us how to use WMI to find the virtual machine's uptime (how long the virtual machine has been running since it was last started or rebooted). The call is displayed in seconds, so he did some tweaking to get it to display nicely.
Set vsWMIObj = GetObject("winmgmts:\\.\root\vm\virtualserver")
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."
Next
Two things to note:
1. Under Virtual Server WMI is only used for reporting statistical counters. There is no way to change anything through WMI, just observe it.
2. You should be careful when using 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.
Read the original and comment, or send Ben a thank you... here.