Using WMI to determine memory usage by Virtual Server

Using WMI to determine memory usage by Virtual Server

  • Comments 1

When you create a virtual machine under Virtual Server, you configure the amount of memory that you want that virtual machine to believe that it has (say 512mb of RAM).  However, Virtual Server needs to use more than that amount of memory to actually run the virtual machine.  Virtual Server also needs memory for itself to run emulated devices and store various information about the virtual machine in.  Unfortunately, because Virtual Server uses a driver (VMM.SYS) to allocate the memory this information is not easily to determine (i.e. it does not show up in task manager).  In the past I posted about how to use PerfMon to see how much memory Virtual Server was actually using, but today I have a nice little VB Script that talks to the Virtual Server WMI interfaces to determine this information.

Now - the fact that Virtual Server has WMI interfaces is very poorly documented - but they do exist and a primarily for gathering statistical information from Virtual Server.  Virtual Server uses a WMI namespace of \\root\vm\virtualserver, and this script connects to that namespace on the local computer, gets a collection of all of the virtual machine objects and then lists out the 'PhysicalMemoryAllocated' property of each virtual machine:

Option Explicit

Dim strComputer, objWMIService, colVMs, vm, totalMem

totalMem = 0
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\vm\virtualserver")
Set colVMs = objWMIService.ExecQuery( _
    "SELECT * FROM VirtualMachine",,48)
For Each vm in colVMs
    Wscript.Echo "-----------------------------------"
    Wscript.Echo vm.name & ":: Physical Memory Allocated: " & _
                        vm.PhysicalMemoryAllocated / 1048576 & _
   " MB (" & vm.PhysicalMemoryAllocated & " bytes)"
    totalMem = totalMem + vm.PhysicalMemoryAllocated
Next

    Wscript.Echo "-----------------------------------"
    Wscript.Echo "All virtual machines"
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "Physical Memory Allocated: " & totalMem / 1048576 _
   & " MB (" & totalMem & " bytes)"

Cheers,
Ben

Leave a Comment
  • Please add 5 and 4 and type the answer here:
  • Post
  • Creates file GetVMRam.ps1 (and then watches IE/ community server doing interesting line wrapping):


    #
    # How much RAM is being used by each VM on the specified server.
    # Based on idea from http://blogs.msdn.com/virtual_pc_guy/archive/2006/09/14/754549.aspx
    #

    Param([string]$ComputerName=(Read-Host "Virtual Server"))

    Get-WmiObject -class VirtualMachine -computername $ComputerName -namespace "root\vm\virtualserver" |
    ft Name,@{e={$_.PhysicalMemoryAllocated/(1024*1024)};l="RAM (MB)"}



    Much shorter than that VBScript...
Page 1 of 1 (1 items)