This script is also already from a while ago, but I’m posting this because it might be useful to anyone that is currently investigating virtual machine limits and reservation performance issues on their environment or are simply looking for a quick check on their environment.

Configuring limits on virtual machine resources such as RAM, CPU cycles and IOPS is not a bad thing to do if the environment needs this to function properly. It can be used to manage situations in which contention comes up, so that your production virtual machines can still use all of the resources they need, but the test environments simply can’t use more resources because of the configured limits. Same goes with reservations. If you want to be sure that your production environments get the resources they need in case of contention, configure a resource reservation on them! This ensures that your production virtual machines always get the amount of resources you have reserved for them. In cases with exteme contention these virtual machines will probably still get slower and have performance impact! Don’t forget to size your environment correctly!

Anyway, a while ago I had to take over another environment and at some point a colleague of mine came to me and said that one of the domain controllers was having performance related issues, but the rest of the virtual machines were not affected. So at that point it directly rang a bell and I told him to check the resource reservations and limits and as you can guess, it had a limit configured which was far less than the amount of configured resources on the virtual machine. After I fixed this by removing the limit, I wanted to check the complete environment so that this could not happen again in the future. For this situation I created the below script:

$VMs = Get-VM

$array = @()

foreach ($VM in $VMs){
	$CPUReservation = $VM | Get-VMResourceConfiguration | Select -ExpandProperty CpuReservationMhz
	$RAMReservation = $VM | Get-VMResourceConfiguration | Select -ExpandProperty MemReservationMB
	$row = "" | Select VMName, MemoryGB, MemoryLimitGB, CPULimit, PleaseFixRAM, PleaseFixCPU
	$row.VMName = $VM.Name
	$row.MemoryGB = $RAM = $VM.MemoryGB 
	$row.MemoryLimitGB = $RAMlimit = $VM | Get-VMResourceConfiguration | Select -ExpandProperty MemLimitGB
	$row.CPULimit = $CPUlimit = $VM | Get-VMResourceConfiguration | Select -ExpandProperty CpuLimitMhz
	if($RAMlimit -ne "-1" -and $RAMlimit -lt $RAM -or $RAMReservation -gt 0){
		$row.PleaseFixRAM += "Yes"
		$row.PleaseFixRAM += "No"
	if($CPULimit -ne "-1" -or $CPUReservation -gt 0){
		$row.PleaseFixCPU += "Yes"
		$row.PleaseFixCPU += "No"
	$array += $row 	
$array | ft

I wanted it to be in some sort of report so that I could have it mailed to myself everytime I take over a new environment. That’s the reason it’s in a table format. This script basically reads all virtual machines in the environment, checks if there is A- a limit on the virtual machine and B- checks if that limit is less than the amount of configured RAM and C- checks if there is any reservation. If the RAM limit is more than what is configured as RAM it doesn’t really matter, because it will never have any impact from the limit (unless you increase the RAM and forget to delete the limit). Secondly it checks the same for the CPU resources. If one of these variables don’t check out, it gives you a nice “PleaseFix” column with a “Yes” or a “No”. See below for some sample output:

VMName MemoryGB MemoryLimitGB CPULimit PleaseFixRAM PleaseFixCPU
------ -------- ------------- -------- ------------ ------------
Bryan         4            -1       -1 No           No

A quick one liner for the limits could also be the following script:

Get-VM | Get-VMResourceConfiguration | ?{($_.MemLimitGB -ne "-1") -or ($_.CpuLimitMhz -ne "-1")} | Select VM, MemLimitGB, CpuLimitMhz

If any of the values under “MemLimitGB” and “CPULimitMhz” are above “-1”, which is unlimited, there is a limit configured of some sorts.

If you want to quickly remove a limit on a virtual machine you could use the following one liner:

Get-VM | Get-VMResourceConfiguration | Set-VMResourceConfiguration -MemLimitMB $null -CpuLimitMhz $null

There you have it, a nice PowerCLI script and a one-liner to do a quick check on your enviroment for limits and reservations together with a quick way to remove them! Want to know more PowerCLI tips and tricks? Click on the button below:

Bryan van Eeden

Bryan is an ambitious and seasoned IT professional with almost a decade of experience in designing, building and operating complex (virtual) IT environments. In his current role he tackles customers, complex issues and design questions on a daily basis. Bryan holds several certifications such as VCIX-DCV, VCAP-DCA, VCAP-DCD, V(T)SP and vSAN and vCloud Specialist badges.


Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *