Memory Reservation Reporting & Changing Values via PowerCLI

I know there are many sources out there for setting values as far as limits are concerned (See Alan Renouf’s blog)with PowerCLI but I could not find anything about setting or removing reservations with commands found in PowerCLI.

I would like to thank Dean Grant (blog here) for the script to report on what VMs have either CPU or Memory reservations that do NOT equal 0. I have made a couple of slight changes as I was wanting to report VMs that only have Memory reservations and that did not match a specific name.

Here is the script for the reporting that will export to a CSV file(again this is mostly the script from Dean’s Blog with a few tweaks):

**Please note that -notlike could be changed to many different options such as -like or -eq. Also to select a specific # of VMs add the following after the closing } on the first line to select the first 5(or a number of your choosing) objects

| Select-object -First 5 

 $(
$VMs = Get-VM | Where-Object {$_.ExtensionData.ResourceConfig.MemoryAllocation.Reservation -ne "0" -and $_.Name -notlike "InsertVMNameHere*"}

ForEach ($VM in $VMs)

{
"" | Select @{N="Name";E={$VM.Name}},
@{N="Memory Reservation";E={$VM.ExtensionData.ResourceConfig.MemoryAllocation.Reservation }}

}
) | Export-Csv C:\FILENAME.CSV

If you are wanting to change the reservations to a specific reservation value AND VM Share value you can use the below script which I had a bit of help from a VERY knowledgeable colleague VirtualServerGuy

**USE AT YOUR OWN RISK**

**Please note that -notlike could be changed to many different options such as -like or -eq. Also to select a specific # of VMs add the following after the closing } on the first line to select the first 5(or a number of your choosing) objects. Also note you need to replace the “#” for the MemReservationMB with a numerical value and you can alert the -MemSharesLevel to High/Low/Normal (or Custom but I have yet to test that) 

$VMs = Get-VM | Where-Object {$_.ExtensionData.ResourceConfig.MemoryAllocation.Reservation -ne "0" -and $_.Name -notlike "InsertVMNameHere*"}

ForEach ($VM in $VMs){

Get-VM $VM | Get-VMResourceConfiguration | Set-VMResourceConfiguration -MemReservationMB "#" -MemSharesLevel Normal

}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s