During a health check of a pre-existing environment using the vCheck script, I found a lot of VMs with Memory Limits configured. After further investigation, these limits did not appear to be on purpose, but perhaps from a previous template or mis-configuration.

Since there were probably about 50 or so, I wanted to attack this in an automated manner instead of manually editing the settings of each VM, comparing configured memory with the limit, and so on. I found a lot of good resources for clearing them in a sweeping manner, but I wanted an approach that would allow me to first get a report of what the configured memory is and what the configured limit is. Unable to find these, I spent a few minutes concocting the following set of commands:

Get-VM | Foreach-Object -Process { Tee-Object -InputObject $_ -Variable Temp | Get-VMResourceConfiguration | where {$_.MemLimitMB -ne ‘-1′} } | Select VM,@{N=”MemoryMB”;E={$Temp.MemoryMB}},MemLimitMB

This returns in a format as follows:

Report Export

So, based on the output there may be some VMs with no real reason to have a memory limit since it is equal to their configured memory anyway, but there are also some that have memory limits much lower than their configured memory. If I just cleared all memory limits, I’d have several machines with memory possibly over-allocated. Instead of clearing them all, I found the ones that had these values equal via the following command:

Get-VM | Foreach-Object -Process { Tee-Object -InputObject $_ -Variable Temp | Get-VMResourceConfiguration | where {$_.MemLimitMB -eq $Temp.MemoryMB} } | Select VM,@{N=”MemoryMB”;E={$Temp.MemoryMB}},MemLimitMB 

Then I went ahead and cleared those via:

Get-VM | Foreach-Object -Process { Tee-Object -InputObject $_ -Variable Temp | Get-VMResourceConfiguration | where {$_.MemLimitMB -eq $Temp.MemoryMB} } | Set-VMResourceConfiguration -MemLimitMB $null 

To reiterate, the aforementioned clears out any memory limits where the limit is the same size as the configured memory. This will spawn sequential tasks within vCenter that, from my runs, took about ~6 seconds each:

Reconfig Recent Tasks

For the list of virtual machines with limits set different from their configured memory, those will be addressed manually with re-sizing if appropriate.