Virtualization Technology News and Information
Article
RSS
CODE: Looking at VM Uptime through WMI

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.

Published Sunday, October 08, 2006 7:46 PM by David Marshall
Filed under:
Comments
There are no comments for this post.
To post a comment, you must be a registered user. Registration is free and easy! Sign up now!
top25
Calendar
<October 2006>
SuMoTuWeThFrSa
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234