Tuesday, September 8, 2015

Automating ESXi host power management policies via powercli

If you have many ESXi hosts and you wanted to get all the juice out of your ESXi (well you paid heavily for it didn't you, so you better get all you can out of it) then you might have thought of changing the power management policy on your esxi hosts. I am not talking about the DPM but the host>configuration>hardware>power management settings.
I want to set it to high performance but you might want to set it to balanced but for the sake of this post let it be high performance which is 1.
First you wanna get the already set value for your 10s or 100s of hosts. you do that with  the following

Get-VMHost | Sort | Select Name,@{ N="CurrentPolicy"; E={$_.ExtensionData.config.PowerSystemInfo.CurrentPolicy.ShortName}},@{ N="CurrentPolicyKey"; E={$_.ExtensionData.config.PowerSystemInfo.CurrentPolicy.Key}},@{ N="AvailablePolicies"; E={$_.ExtensionData.config.PowerSystemCapability.AvailablePolicy.ShortName}}

If you want to set it then you might want to do it like this

$view = (Get-VMHost $VMHost   | Get-View)
(Get-View $view.ConfigManager.PowerSystem).ConfigurePowerPolicy(1)

replace the $VMHost with your hostname
 Please note that the above value is set to 1 which means performance. The other values are


1=HighPerformance /2=Balanced /3=LowPower

Now you might want to shorten it like this
{(Get-View (Get-VMHost $VMHost | Get-View).ConfigManager.PowerSystem).ConfigurePowerPolicy(1)}

What if you want to do the same for many hosts, well powershell looping got you covered.

foreach ($VMHost in (Get-VMHost)){(Get-View (Get-VMHost $VMHost | Get-View).ConfigManager.PowerSystem).ConfigurePowerPolicy(1)} 

and if you are feeling even lazier than I am then here is a shortest oneliner that I could think of for this

(Get-View (Get-VMHost | Get-View).ConfigManager.PowerSystem).ConfigurePowerPolicy(1)

So that's it folks, for more info check out the vmware communities link for the same.
https://communities.vmware.com/thread/461039