Scripting dynamic memory, part 1: reading the configuration

Scripting dynamic memory, part 1: reading the configuration

  • Comments 2

With the availability of dynamic memory in Windows Server 2008 R2 SP1 there are some changes to how you need to handle memory as a scripter / developer.  The WMI API changes are now documented here http://msdn.microsoft.com/en-us/library/cc136856(VS.85).aspx

Most of the changes are fairly obvious – but two not so obvious properties are the properties for the “Startup RAM” and “Maximum RAM”.  In WMI these are mapped to “VirtualQuantity” and “Limit” respectively.  Here is a sample script that simply displays the memory configuration of the specified virtual machine:

# Prompt for the Hyper-V Server to use
$HyperVServer = Read-Host "Specify the Hyper-V Server to use (enter '.' for the local computer)"
 
# Prompt for the virtual machine to use
$VMName = Read-Host "Specify the name of the virtual machine"
 
# Get the management service
$VMMS = gwmi -namespace root\virtualization Msvm_VirtualSystemManagementService -computername $HyperVServer
 
# Get the virtual machine object
$VM = gwmi MSVM_ComputerSystem -filter "ElementName='$VMName'" -namespace "root\virtualization" -computername $HyperVServer
 
# SettingType = 3 ensures that we do not get snapshots
$SystemSettingData = $VM.getRelated("Msvm_VirtualSystemSettingData") | where {$_.SettingType -eq 3}
 
# Get the Memory setting data
$MemSetting = $SystemSettingData.getRelated("Msvm_MemorySettingData") | select -first 1
 
# Display information about the current memory configuration
switch ($MemSetting.DynamicMemoryEnabled)
   {
      True  {# Dynamic memory is enabled
             write-host
             write-host "Dynamic memory is enabled."
             write-host
             write-host "Startup Memory: " $MemSetting.VirtualQuantity $MemSetting.AllocationUnits
             write-host "Maximum Memory: " $MemSetting.Limit $MemSetting.AllocationUnits
             write-host "Memory buffer:  " $MemSetting.TargetMemoryBuffer
             write-host "Weight:         " $MemSetting.Weight}
                  
      False {# Dynamic memory is disabled
             write-host
             write-host "Dynamic memory is disabled."
             write-host
             write-host "Memory: " $MemSetting.VirtualQuantity $MemSetting.AllocationUnits
             write-host "Weight: " $MemSetting.Weight}
   }

Cheers,
Ben

Attachment: ReadDMConfig.zip
Leave a Comment
  • Please add 2 and 3 and type the answer here:
  • Post
  • I have been searching for a while to find some kind of explanation for how guests talk to the host to accomodate the dynmamic memory adjusments.  In my experience, I've found that if the host and guest are on separate VLANS for their primary network traffic, the guest OS will never adjust from its startup RAM. So, in other words, if I want to use Dynamic memory, I have to use the same vlan and IP scheme on both the Guest and the Host OS in order for the feature to work.

    Is this true?

  • Hi Stephen -

    No, networking is not used at all.  I am not sure why you are seing this - but being on a different network will not be the cause.

    Cheers,

    Ben

Page 1 of 1 (2 items)