|
Last week I posted an article that talked about what happens on an ESX Server when a virtual machine has a memory limit set lower than the amount of memory assigned to that virtual machine. Sound confusing? If so, head over and read the original blog post. The short version is that the situation is simply not good, and has major performance implications across the ESX Host, and potentially across the whole infrastructure. Today, I want to show how you can simply identify and resolve this significant VMware Infrastructure issue using some simple PowerShell commands.
In order to use PowerShell scripting to resolve this issue you will need two components at a minimum: 1.      Microsoft Windows PowerShell – Command line shell and scripting language that helps IT professionals achieve greater control and productivity (I ripped this off from Microsoft’s website) 2.      VMware Infrastructure Toolkit – Powerful yet simple command line interface for task based management of the VMware Infrastructure Platform (again, stolen) 3.      {OPTIONAL] Virtualizaiton EcoShell – Desktop application for novice and expert IT administrators leveraging Windows PowerShell scripts across their multi-platform virtual environments Once you have the two required components installed on a Windows system you are well on your way to a whole new world of managing your VMware environment, but today we just want to focus on a small portion…resolving memory limit configuration issues. Start by opening the “VMware VI Toolkit†console (Or the VESI Script Editor if you installed Virtualization EcoShell). For the purpose of this post, I’m going to assume that everyone knows how to work with a console and hope that most people have some PowerShell experience. This post is not a “How to use PowerShell tutorialâ€. Once you are in the VI Toolkit console, you must first connect to your ESX Host or VirtualCenter server using the following command…replace the ServeName, username, and password with your own configuration. Connect-VIServer ServerName –User username –Password password Once you have a connection established you can query a list of Virtual Machine resource configuration settings with the following command:
Get-VM | Get-VMResourceConfiguration This will provide a list of all virtual machines and their resource configuration settings. We can drill this down to identify only virtual machines whose memory limit is NOT set to unlimited with the following command:
Get-VM | Get-VMResourceConfiguration | where {$_.MemLimitMB -ne '-1'} If this command does not return any data, congratulations, you do not have any virtual machines that have a hard memory limit configured. If you do have objects that are returned, it means there are potential configuration errors for your virtual machines. What you optimally want is for all of your virtual machines to have their memory limit set to “unlimitedâ€. Again, using the capabilities of PowerShell, we can extend onto our command again to resolve any potential configuration issues. Note the backtick at the end of the first line. This indicates the command should continue as if it were on a single line, but I ran out of space.
Get-VM | Get-VMResourceConfiguration | where {$_.MemLimitMB -ne '-1'} `     | Set-VMResourceConfiguration -MemLimitMB $null It is important to note that the above script does not give you the option to ignore a particular VM. While I cannot personally think of any reason to modify this default behavior for Memory Limits, it doesn’t mean a valid reason doesn’t exist somewhere. Because of this, I have created a fully interactive script that allows someone to Query all VM Configurations, Identify potential configuration errors, and Resolve select virtual machines. The QueryMem.ps1 file, which is attached at the bottom of this blog post, can be used in one of three modes: Query Resource Allocations:     QueryMem.ps1 -VMHost server1.domain.com -User administrator -Password passw0rd -Action query Idenfity Potential Misconfigurations:     QueryMem.ps1 -VMHost server1.domain.com -User administrator -Password passw0rd -Action id Modify Misconfigured VMs:     QueryMem.ps1 -VMHost server1.domain.com -User administrator -Password passw0rd -Action resolve `          -vm vm1, vm2, vm3
Attachments:
| File | Description | File size | Downloads |
QueryMem.ps1 | PowerShell sacript to identify and resolve Memory Limit configuration issues | 2 Kb | 531 |
Trackback(0)
|