Virtual Network Statistics from WMI

Continuing with my journey through the undocumented lands of Virtual Server WMI we come to virtual network statistics. This nice little script displays information about virtual network name, and the number of packets and bytes that have been sent received and dropped on each virtual network:

Option Explicit

Dim vsWMI, vns, vn

Set vsWMI = GetObject("winmgmts:\.rootvmvirtualserver")
Set vns = vsWMI.ExecQuery( "SELECT * FROM VirtualNetwork",,48)
For Each vn in vns
Wscript.Echo "-----------------------------------"
Wscript.Echo "Virtual Network: " & vn.Name
Wscript.Echo "-----------------------------------"
Wscript.Echo "Packets Sent: " & vn.PacketsSent & _
" (" & vn.BytesSent & " bytes)"
Wscript.Echo "Packets Received: " & vn.PacketsReceived & _
" (" & vn.BytesReceived & " bytes)"
Wscript.Echo "Packets Dropped: " & vn.PacketsDropped & _
" (" & vn.BytesDropped & " bytes)"
Next

One oddity about the WMI interface here is that you will only see information about virtual network for which there is a currently running virtual machine connected.

Cheers,
Ben