On a Windows 2012 R2 virtual machine running under Hyper-V, Task Manager has the ability to display a virtual machine's maximum memory when the virtual machine is using dynamic memory, as shown in the screenshot below.

enter image description here

I've tried navigating through the following classes but I can't find what I need:

  • Win32_OperatingSystem (TotalVisibleMemorySize only shows what the VM has consumed so far - not what the maximum is)
  • Win32_PhysicalMemory
  • Win32_PhysicalMemoryArray
  • Win32_ComputerSystem (TotalPhysicalMemory only reports the same as TotalVisibleMemorySize above - i.e. the first of the Committed memory values)

Is it possible to programatically query using WMI or Registry to obtain this Maximum Memory value from inside the virtual machine itself?


Modern operating systems (Windows 8/2012 and newer) includes a class named Win32_PerfRawData_Counters_HyperVDynamicMemoryIntegrationService under the namespace root\cimv2

This class has a property named MaximumMemoryMBytes which shows the maximum memory, also seen in Windows 2012 and above Task Managers.

VBScript Sample Code:

Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PerfRawData_Counters_HyperVDynamicMemoryIntegrationService",,48)
For Each Item in colItems
    Wscript.Echo "Maximum memory in Megabytes  " & Item.MaximumMemoryMbytes

Powershell sample code:

Get-WmiObject -namespace root\cimv2 -class Win32_PerfRawData_Counters_HyperVDynamicMemoryIntegrationService | Select-Object MaximumMemoryMBytes

This class does not exist in Windows 2008 R2/Windows 7 or earlier operating systems.

More information about this class can be found here


I know I'm late, but I got troubled by this for a long time so...

Get-Counter "\Hyper-v Dynamic Memory Integration Service\Maximum Memory, Mbytes"

As far as I understand, the VM doesn't know if dynamic memory is enabled, it only knows how many memories have been allocated and the memory cap.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.