PowerCLI - Configure multiple ESXi Power Policy
This is a quick powershell script that setups up ESXi Power Policies in all the hosts in a cluster or vCenter.
Script Parameters
- Mandatory
- vCenter » vCenter FQDN/IP to connect too
- vCenterUsername » vCenter Username
- vCenterPassword » corresponding password
- powerProfile » Power Profile config to use:
- High Performance
- Balanced
- Low Power
- Custom
- Optional
- cluster » Cluster name if we want to change the hosts from a single cluster
The code is pretty simple, but it worth to point out the relevant parts of it
- Hash Table to adapt/translate the common name of the Power Policies to the right value needed by the ConfigurePowerPolicy method
# Keys for the values needed for the ConfigurePowerPolicy method
$powerProfiles = @{
"High Performance" = 1 ;
"Balanced" = 2 ;
"Low Power" = 3 ;
"Custom" = 4
}
- List the current status
$currentState = $vmHosts | Sort-Object $_.Name| `
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}}
$currentState | Format-Table -AutoSize
- Change effectively the Power Policy
# Set the PowerProfile to the desired state
(Get-View ($vmHosts | `
Get-View).ConfigManager.PowerSystem).ConfigurePowerPolicy($powerProfiles.$powerProfile)