We here at VMware often get requests by people who are trying to tweak the default resource allocations that VMs have. This post shows you how easy it is to automate configuring and changing resource allocations is when using PowerShell.
First, a bit of background information. Each VM has a certain level of CPU and memory shares. In addition these levels may be limited or unlimited. Even further, a VM can have CPU or memory reservations, which means the VM will always have at least this minimal level of resources available to it. When shares are unlimited, a VM may receive more resources than its share allocation, provided these resources are not being used by some other VM.
By default, a VM gets normal CPU and memory shares with no reservation and no limit. This is a sensible default, but many times you want to tune this to improve performance for some applications.
This first example shows you how to set all VMs in your entire Virtual Infrastructure to high CPU shares and no limit.
|
This script works whether you have 1 VM or 1,000 VMs. The next example shows how to set a VM’s memory allocation to normal, with no limit, and ensure that each VM has at least 1 GB of memory.
|
Chances are these are not quite the policies you’re looking for, but you easily determine what values you want by referring to the VMware API Reference Guide.
This is extremely powerful, but it’s even more so when you consider that you can combine it with cmdlets like
1 |
Get-ResourcePool |
and
1 |
Get-Folder |
to select exactly the VMs you want to modify. For example, using
1 |
Get-ResourcePool |
you could very easily set all VMs in one resource pool to have CPU resources set to high and all VMs in another resource pool to have CPU resources set to low.
This is just one of the great things you can do when you manage VMware with PowerShell, so if you haven’t looked at it yet you should definately download the VI Toolkit (for Windows) Beta.