Home > PowerShell, vRAM, vSphere > Query vRAM

Query vRAM

After the Cloud Infrastructure Launch Forum event from July 12th 2011, it seemed that the new licensing model attracted more blog posts and tweets than the 140 new features in vSphere 5.

As one could imagine, one of the most heard questions was, what will I need to pay in the new licensing model. As a pro-active measure, I decided to write a short script that would tell me what vRAM entitlement my current vSphere 4 licenses would offer me.

Update August 4th 2011 08:30: VMware updated the vRAM calculation specifications. See the VMware vSphereβ„’ 5.0 Licensing, Pricing and Packaging White Paper.

Update July 13th 2011 14:45: Apparently you have a vRAM pool per license type. I updated the script.

The script

function Get-vRAMInfo{
  $memoryCapMB = 96 * 1KB
  $vRAMtab = @{

  $licMgr = Get-View LicenseManager
  $licAssignMgr = Get-View $licMgr.LicenseAssignmentManager

  $totals = @{}

  Get-VMHost | %{
    $lic = $licAssignMgr.QueryAssignedLicenses($_.Extensiondata.MoRef.Value)
    $licType = $lic[0].AssignedLicense.EditionKey
    $totalvRAM = ($vRAMtab[$licType] * $_.Extensiondata.Hardware.CpuInfo.NumCpuPackages)

    $VMs = Get-VM -Location $_
    $vmRAMConfigured = ($VMs | `
    Select -Property @{N="CappedMemoryMB";
      E={if($_.MemoryMB -lt $memoryCapMB){$_.MemoryMB}else{$memoryCapMB}}} | `
      Measure-Object -Property CappedMemoryMB -Sum).Sum/1KB
    $vmRAMUsed = ($VMs | where {$_.PowerState -eq "PoweredOn"} | `
      Select -Property @{N="CappedMemoryMB";
      E={if($_.MemoryMB -lt $memoryCapMB){$_.MemoryMB}else{$memoryCapMB}}} | `
      Measure-Object -Property CappedMemoryMB -Sum).Sum/1KB

      $totals[$licType].vRAMEntitled += $totalvRAM
      $totals[$licType].vRAMConfigured += $vmRAMConfigured
      $totals[$licType].vRAMUsed += $vmRAMUsed
      $totals[$licType] = New-Object PSObject -Property @{
        vCenter = $defaultVIServer.Name
        LicenseType = $lic[0].AssignedLicense.Name
        vRAMEntitled = $totalvRAM
        vRAMConfigured = $vmRAMConfigured
        vRAMUsed = $vmRAMUsed
  $totals.GetEnumerator() | %{
    New-Object PSObject -Property @{
      vCenter = $_.Value.vCenter
      LicenseType = $_.Value.LicenseType
      vRAMEntitled = $_.Value.vRAMEntitled
      vRAMConfigured = [Math]::Round($_.Value.vRAMConfigured,1)
      vRAMUsed = [Math]::Round($_.Value.vRAMUsed,1)


Line 3-7:Β  The vRAM entitlement per type of license is stored in a hash tab.

Line 6: The script doesn’t take into account that the Advanced licenses will be converted to Enterprise.

Line 16: Note, the current version of the script only uses allocated licenses to calculate your vRAM entitlement. If you happen to have unallocated licenses, they will currently not be reflected in your vRAM entitlement.

Line 17: The script uses the QueryAssignedLicenses method. Unfortunately this only works for vSphere 4.1 and higher.

Line 22: Calculate the amount of configured RAM for the guests. This will give the potential maximum vRAM you could need.

Line 23: Calculate the amount of RAM used by powered on guests

Sample run

Just call the function: Get-vRAMInfo.

It will produce something like this.

If your vRAMUsed amount turns out to be higher than your vRAMEntitled amount, you will have to acquire extra licenses.

In my test environment I don’t need additional licenses πŸ˜†

Categories: PowerShell, vRAM, vSphere Tags: , ,
  1. Marc
    December 1st, 2011 at 22:04 | #1

    Can I run this against ESXi host or do I need Vcenter?


    • December 1st, 2011 at 22:55 | #2

      @Marc, I’m afraid the script is intended to be run against vCenter.

  2. Korey Klier
    August 24th, 2011 at 18:20 | #3

    I’m admitted new to Powershell. I’m having a bit of trouble with this function. I’ve connected to my vcenter(v4.1), I’ve sourced the Powershell script, but I am receiving several errors.

    Get-View : Cannot validate argument on parameter ‘Id’. The argument is null or
    empty. Supply an argument that is not null or empty and then try the command ag
    At C:\cdns\bin\Get-vRamInfo.ps1:13 char:27
    + $licAssignMgr = Get-View <<<< $licMgr.LicenseAssignmentManager
    + CategoryInfo : InvalidData: (:) [Get-View], ParameterBindingVal
    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutom

    You cannot call a method on a null-valued expression.
    At C:\cdns\bin\Get-vRamInfo.ps1:18 char:47
    + $lic = $licAssignMgr.QueryAssignedLicenses <<<< ($_.Extensiondata.MoRef.V
    + CategoryInfo : InvalidOperation: (QueryAssignedLicenses:String)
    [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    Cannot index into a null array.
    At C:\cdns\bin\Get-vRamInfo.ps1:19 char:21
    + $licType = $lic[ <<<< 0].AssignedLicense.EditionKey
    + CategoryInfo : InvalidOperation: (0:Int32) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

    I'm sure I'm missing something.

    • August 24th, 2011 at 20:21 | #4

      @Korey, let’s start from the beginning.
      Did you connect to the vCenter before running the script ?

      Connect-VIServer -Server MyVC

  3. Aaron
    August 9th, 2011 at 15:07 | #5

    I’ve just installed the PowerCLI (VMware-PowerCLI-4.1.1-332441). Unfortunately when I run your script nothing at all is happening. Any ideas?

    • August 9th, 2011 at 20:10 | #6

      @Aaron, are you running this against a vSphere 4.1 installation ?
      Unfortunately the script will not work for pre-4.1 versions.

  4. July 19th, 2011 at 16:27 | #7

    Please take the time to fill out this vSphere 5 migration survey:

    We need more data! Will be posting results in the VMTN thread: http://communities.vmware.com/thread/320877.

  5. July 14th, 2011 at 11:19 | #8

    Hi Luc,
    very good job!
    I’d only like the script to take into account not only the currently assigned CPU licenses, but also the unassigned ones, because they would also add up to the vRAM entitlements with vSphere 5.
    – Andreas

    • July 14th, 2011 at 13:06 | #9

      @Andreas, that is a good suggestion.
      I’ll try to incorporate that in a new version.

  6. Kerrod Wells
    July 14th, 2011 at 03:30 | #10

    Thanks for making this available. A quick upgrade to our PowerCLI and it worked perfectly.

    Thankfully no new licenses needed for us at this stage.

  7. July 14th, 2011 at 02:49 | #11


    I guess currently we are about 106 pCPU – with 1928 GB of vRam. By upgrading our licenses we are at 5088 GB of Entitled vRAM (All ent + shop). We planned on migrating/consolidating our clusters to only 42 CPU’s total which would put us right at 2016 if we did it after migrating. This means we would have to purchase more licenses for future capacity. But if we upgraded all our licenses (which wont happen) we wouldn’t have to worry about a thing. So in the long run it doesn’t really affect shops and there is also not a lot of information on prior vsphere 4 updating cost. I am under the impressions we negotiated our licenses to vSphere 4 prior but just have completed the upgrade. Either way we are going to have to be more tactical to not put ourselves in a bind.

  8. Chad King
    July 14th, 2011 at 02:28 | #12

    I would love to post mine to show how much this licensing model is going to screw us over but obviously we aren’t all 4.1 like some people ;). I already had a colleague say to me on the phone “I have to budget for 40 more licenses for our p2v for the rest of our environment is going to have to wait, we weren’t scaling out, we were scaling up” – Sadly, for some folks they are going to look else where especially in businesses where low cost is important like logistics. I will post mine but I am sure ours will probably fall into the vmware sweet spot – lol.

  9. Chad King
    July 14th, 2011 at 02:24 | #13

    too bad its just for 4.1 – that kind of sucks imo.

    We have a very diverse environment even some host on 3.5 still. Anyways, I am sure we wont be paying more but this def changes the name of the game for us because we gage on capacity not vRAM.

  10. July 14th, 2011 at 02:21 | #14

    Hi all… I started a thread here in the hop that people will post the results.


  11. OfficeGlen
    July 14th, 2011 at 01:32 | #15

    For some reason I my vSphere 4 Standard licenses are reporting as the edition type “esxFull” instead of esxStandard

    To fix I added the follow line to the $vRAMtab array:

    Without that line my vRAMEntitled amount for vSphere Standard was not displaying a value.

    • July 14th, 2011 at 07:24 | #16

      @OfficeGlen, thanks for the info. I updated the table.
      As you can imagine I don’t have all the license types present in my test environment πŸ™‚

      If some of the other licensekeys are not correct, please let me know!

  12. July 14th, 2011 at 00:38 | #17

    Thanks for writing this

    Seems to imply you can make more efficient use of your entitlement by ratcheting down the unused memory allocation per VM
    (Therefore a script to show the most overallocated VMs in terms of memory would logically be next!?)

    • July 14th, 2011 at 07:05 | #18

      @Fletch00, that will be indeed the logical follow-up post πŸ™‚

  13. John Dias
    July 14th, 2011 at 00:05 | #19

    @John K
    Same here and I’m running build 332441

    • July 14th, 2011 at 07:05 | #20

      @John, did you run the script against a pre-4.1 vCenter ?
      For pre-4.1 the current script will not work due to the differences in the LicenseManager methods in the API.

  14. Wayne
    July 13th, 2011 at 19:35 | #21


    We’re using vSphere 4.0 u2

    • July 13th, 2011 at 20:05 | #22

      That’s the reason, pre 4.1 the vSphere License Manager is different.
      The call the script makes to collect the license information will not return anything.
      Let me check if I can script pre 4.1 support for the script.

    • July 13th, 2011 at 21:37 | #23

      The current script only will work for vSphere 4.1 and higher. The reason is that the QueryAssignedLicenses method doesn’t work for earlier vSphere versions πŸ™

  15. Wayne
    July 13th, 2011 at 19:13 | #24

    I’m getting the same results as Benjamin. I’ve ran connect-viserver and I’m using snapin version:
    VMWare vSphere PowerCLI 4.1 U1 build 332441


    • July 13th, 2011 at 19:28 | #25

      I tested the script against in a vSphere 4.1U1 environment.
      Are you perhaps using another version ?

  16. John K
    July 13th, 2011 at 19:09 | #26


    Weird, I’m getting no result either even when adding ‘connect-viserver myvc’ to the script

  17. Andy
    July 13th, 2011 at 18:48 | #27

    What kind of results are you seeing – is the new model going to hurt or help you

    • July 13th, 2011 at 18:55 | #28

      @Andy, in our environment we are covered, no need to acquire extra licenses.
      But as it was mentioned in other fora and tweets, it all depends (size of your VMs, type of licenses you currently have, your VM density per processor…).
      I’m sure the last word about this hasn’t been said yet πŸ™‚

  18. Benjamin
    July 13th, 2011 at 18:43 | #29

    Are you using only the powercli snap-in? I run this and no output at all, just returns to the command line.

    • July 13th, 2011 at 18:47 | #30

      @Benjamin, the script only uses the (latest) PowerCLI snapin.
      And you have to have made the connection to the vCenter before calling the function.

      Connect-VIServer -Server myVC

  19. July 13th, 2011 at 16:50 | #31

    Awesome script as usual Luc, like the update, certainly makes things a little more clarified πŸ™‚

  20. Troy Clavell
    July 13th, 2011 at 16:16 | #32

    Good Stuff!!

  21. July 13th, 2011 at 15:36 | #33

    Hi Luc and Hugo,

    Great scripts. But since you’re querying the VMs anyway, maybe also query how much RAM on average they really use. So it will tell me that the VM I gave 6GB only uses 4GB. And that I can save 2GB on that VM.


  22. July 13th, 2011 at 15:35 | #34

    Great script Luc,

    It would be good if people could post the results.


    • July 13th, 2011 at 15:41 | #35

      Thanks Duncan, that is indeed a good idea and would provide some actual input to the theoretical discussion that is going on since yesterday.

  23. July 13th, 2011 at 15:33 | #36

    “Increasing the Pooled vRAM Capacity
    If necessary, the easiest way to expand pooled vRAM capacity
    is to add more vSphere CPU licenses of the same edition to
    the vRAM pool. Alternatively, customers can upgrade all CPU
    licenses in the vRAM pool to a vSphere edition with a higher
    base vRAM entitlement.”

    I do not see where it says one way or another if you are able to have multiple vRAM pools on the same vCenter server or Linked vCenter Servers. They imply that if you have a vCenter server or linked vCenter servers they work as a single vRAM pool/entitlement. But also give indication based on management of pools that it is vCenter server specific.

    It does seem reasonable however that you could have multiple vCenter servers at different licensing levels.

    “As long as the total consumed
    vRAM across all virtual machines managed by a VMware vCenter
    instance or multiple linked VMware vCenter instances is less or
    equal to the total available vRAM, vSphere is correctly licensed.”

    In conclusion I’d say it goes as follows:
    1. Each vCenter server has one level of licensing and that vCenter server has it’s own vRAM pool.
    2. If you have multiple vCenter servers linked then you can share memory between the vRAM pools to come up with your total vRAM entitlement.
    3. You can add a license on any of your linked vCenter servers to increase your overall vRAM entitlement but my gut tells me that could let people cheat on feature differences between versions.

    If this is the case then management of this will be a nightmare without some really good tools.

    • July 13th, 2011 at 15:39 | #37

      @Josh, that was my interpretation as well at first, but the majority of the commenters seem to agree that there is a vRAM pool per license type.
      Perhaps VMware will release a clarification statement in the coming hours/days.

  24. Rob Upham
    July 13th, 2011 at 15:16 | #38

    Hi Luc … The other folks are correct – check the last paragraph on Page 7 of the PDF:
    “Note that all hosts in a vRAM pool must be licensed with the same vSphere edition or, in other terms, vRAM entitlements are pooled by vSphere Edition. It is possible to manage mixed environments of hosts licensed with different vSphere Editions from the same
    vCenter, however this will create multiple vRAM pools. vRAM capacity can only be shared among servers licensed with the same vSphere Edition.”

    • July 13th, 2011 at 15:28 | #39

      Rob/Mark/Dan/Didier, thanks for the confirmation.
      I updated the script, it now returns the vRAM pool information per license type.
      At least I learned something today πŸ™‚

  25. Mark
    July 13th, 2011 at 14:31 | #40


    Based on the FAQ in http://www.vmware.com/files/pdf/vsphere_pricing.pdf the vRAM pools are by edition so it is not one global pool but actually 5.

  26. July 13th, 2011 at 14:05 | #41


    Hello again πŸ™‚

    It’s in the Q&A bit at the end, as well as other places:

    Q: What is the available pooled vRAM capacity of my environment?
    A: Available pooled vRAM is equal to the sum total of vRAM entitlements for all vSphere licenses of a single edition, managed by a single instance of VMware vCenter Server or by multiple instances of VMware vCenter Server in Linked Mode.


  27. July 13th, 2011 at 14:05 | #42

    @LucD Indeed you cannot mix different license types…

  28. July 13th, 2011 at 13:09 | #43


    Hey Luc,
    Licenses have to be of the same type, you can’t pool “standard” with “enterprise plus” from what I’ve read.
    Also, it appears vRAMused should not exceed vRAMEntitled rather than vRAMConfigured as the licensing documents say that “when a VM is powered on, the vRAM configured counts against the vRAM entitlement”…


    • July 13th, 2011 at 13:21 | #44

      @Dan, thanks for the vRAMUsed remark. That was indeed a typo in the last paragraph. It’s corrected.
      On the vRAM pooling principle, I’m not sure that you can’t mix license types in the calculation of the vRAM pool. I have reread the white paper, but can’t find where it says this explicitely. Please correct me if I’m wrong, this is new for all of us I assume πŸ˜‰

  29. July 13th, 2011 at 12:36 | #45


    Awesome job. I’ll bookmark this!


  30. July 13th, 2011 at 11:58 | #46

    Hey Luc!
    Great minds think alike πŸ˜‰
    I like how you use the license manager in stead of the actual pCpu count. One thing I added though, is show how many additional licenses you’d need if you are over your vRAM entitlement.

    • July 13th, 2011 at 12:05 | #47

      Lol. Giving the number of required licenses is indeed a great feature, but I deliberately left that out, because I think that the pooled vRAM concept, offers the possibility to acquire extra licenses to increase the total vRAM, not necessarily of the same type.

  1. July 13th, 2011 at 13:48 | #1
  2. July 13th, 2011 at 17:17 | #2
  3. July 13th, 2011 at 19:53 | #3
  4. July 13th, 2011 at 21:53 | #4
  5. July 14th, 2011 at 06:57 | #5
  6. July 15th, 2011 at 13:00 | #6
  7. July 16th, 2011 at 01:01 | #7
  8. July 22nd, 2011 at 13:12 | #8
  9. July 25th, 2011 at 07:03 | #9
  10. August 2nd, 2011 at 09:29 | #10
  11. August 4th, 2011 at 09:06 | #11
  12. August 4th, 2011 at 09:18 | #12
  13. October 27th, 2011 at 02:10 | #13