Remove vmware memory limits with Powershell
Using Memory Limits in vmware vSphere can cause severe performance issues. The guest operating system assumes it can use all of the allocated memory, but vSphere will make sure the vm cannot use more than the memory limit. It does this by inflating a memory balloon using the balloon driver included with the vmware tools. The performance chart in the vSphere Client will show the virtual machine is ballooning. I never recommend using memory limits in vmware.
The following script will remove all memory limits in your vSphere infrastructure, preventing the problems described above.
$vCenterServer = MyvCenterServer.domain.local #Enter your vCenter server FQDN here #Connect to vCenter Server $VC = Connect-VIServer $vCenterServer #Gathering data ForEach ($vm in get-vm) { $vmView = $vm | get-view Write-Host "======" Write-Host "VM: $($vm.Name)" Write-Host "Current Limit: $($vmView.config.MemoryAllocation.Limit)" If ($vmView.config.MemoryAllocation.Limit -ne -1) { #Preparing modified data $spec = New-Object VMware.Vim.VirtualMachineConfigSpec $MemoryAllocation = New-Object VMware.Vim.ResourceAllocationInfo $MemoryAllocation.Limit = -1 $spec.MemoryAllocation = $MemoryAllocation #Applying modification Write-Host "Removing Memory Limit" $vmView.ReconfigVM($spec) #Reloading data $vm = get-vm $vm.name $vmView = $vm | get-view Write-Host "Current Limit: $($vmView.config.MemoryAllocation.Limit)" } #Cleanup Clear-Variable vmView -ErrorAction SilentlyContinue } #Disconnect Disconnect-VIServer $vCenterServer -Confirm:$false |
You can download the script here (rename to .ps1): Remove-MemoryLimits
Don’t forget to use PowerCLI to run the script, or add the PowerCLI snapin to your Powershell session (Add-PSSnapIn vmware*).
Enjoy!
3 Responses to Remove vmware memory limits with Powershell
Tags
Active Directory API bind order cleanup cluster CPU Custom Fields datastores description device management directory tree errors Event Log file name filter Fun function HA IT known issues License Server LUN multipath NIC objects Oneliner portgroups PowerCLI PowerShell profile recursive Registry Scripts security session share snapshots SQL Stat VI Toolkit VMware vSphere WMI WSUS ZenArchives
- July 2012
- July 2011
- February 2011
- January 2011
- December 2010
- May 2010
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008





New in PowerCLI 5.0: this can be reduced to a simple oneliner:
Or ever better:
Get-VM| Get-VMResourceConfiguration | Where {$_.MemLimitMB -ne -1} | Set-VMResourceConfiguration -MemLimitMB $nullGreat stuff and your update yesterday for PowerCLI 5.0 was quite timely! Just found a bunch of VMs in our environment that were erroneously configured with a memory limit. Some were in the tragic state of ballooning or even swapping needlessly since they were artificially starved. What could have quite possibly have taken hours to fix turned into a few minutes with this script. Thank you for sharing!