<?xml version="1.0" encoding="UTF-8"?>        <rss version="2.0"
             xmlns:atom="http://www.w3.org/2005/Atom"
             xmlns:dc="http://purl.org/dc/elements/1.1/"
             xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
             xmlns:admin="http://webns.net/mvcb/"
             xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
             xmlns:content="http://purl.org/rss/1.0/modules/content/">
        <channel>
            <title>
									PowerCLI Script to change Power Management Active Policy on Standalone host or cluster - VMware vSphere help				            </title>
            <link>https://www.virtualizationhowto.com/community/vmware-vsphere-help/powercli-script-to-change-power-management-active-policy-on-standalone-host-or-cluster/</link>
            <description>Virtualization Howto Discussion Board</description>
            <language>en-US</language>
            <lastBuildDate>Sun, 16 Aug 2026 16:33:13 +0000</lastBuildDate>
            <generator>wpForo</generator>
            <ttl>60</ttl>
							                    <item>
                        <title>PowerCLI Script to change Power Management Active Policy on Standalone host or cluster</title>
                        <link>https://www.virtualizationhowto.com/community/vmware-vsphere-help/powercli-script-to-change-power-management-active-policy-on-standalone-host-or-cluster/#post-951</link>
                        <pubDate>Wed, 25 Sep 2024 15:39:11 +0000</pubDate>
                        <description><![CDATA[I have been writing a lot lately about power management, power consumption, and enabling low-power modes for home lab environments, as this is extremely important when thinking about running...]]></description>
                        <content:encoded><![CDATA[<p>I have been writing a lot lately about power management, power consumption, and enabling low-power modes for home lab environments, as this is extremely important when thinking about running a home lab 24x7x365. It helps to make sure that your server runs as efficiently as possible without spinning unnecessary CPU cycles and power when idle.</p>
<p>If you want an easy way to automate the process of setting the power management active policy for your ESXi host, PowerCLI is a great way to do this. Check out the code below:</p>
<p>Here is a summary of what the script will do:</p>
<ul>
<li><strong>Check to see if you connected:</strong> If not connected, you will be asked to connect to a vCenter server</li>
<li><strong>Cluster or standalone:</strong> It will prompt you whether you want to configure a cluster or a standalone host</li>
<li><strong>Nam:</strong> Enter the name of the cluster or host you want to configure</li>
<li><strong>Select the power policy:</strong> Choose a power policy (High Performance, Balanced, or Low Power)</li>
<li><strong>Confirmation:</strong> The script will confirm whether or not it was able to apply the power policy settings to the host or cluster</li>
</ul>
<p>Ok, so here is the script for you to use, enjoy!</p>
<pre contenteditable="false"># Check if connected to any vCenter Server
$connected = $false
$servers = Get-VIServer
foreach ($server in $servers) {
    if ($server.IsConnected) {
        $connected = $true
        break
    }
}

# If not connected, prompt for connection
if (-not $connected) {
    Write-Host "Not connected to any vCenter Server. Please connect to a vCenter Server."
    $vCenterServer = Read-Host "Enter the vCenter Server name or IP"
    Connect-VIServer -Server $vCenterServer

    # Check if the connection was successful
    $connectedServer = Get-VIServer | Where-Object {$_.IsConnected}
    if (-not $connectedServer) {
        Write-Host "Failed to connect to the vCenter Server. Please try again."
        exit
    }
}

# Function to get the power policy code based on user input
function Get-PowerPolicyCode {
    param (
        $policy
    )

    switch ($policy.ToLower()) {
        "high performance" { return 1 }
        "balanced" { return 2 }
        "low power" { return 3 }
        default {
            Write-Host "Invalid power policy. Please choose between 'High Performance', 'Balanced', or 'Low Power'."
            exit
        }
    }
}

# Prompt user to select target type (cluster or standalone host)
$targetType = Read-Host "Do you want to configure a Cluster or a Standalone Host? (Enter 'Cluster' or 'Host')"

# Initialize variables
$vmhosts = @()

# Get the target based on user input
if ($targetType -eq "Cluster") {
    $clusterName = Read-Host "Enter the name of the Cluster"
    $vmhosts = Get-Cluster -Name $clusterName | Get-VMHost
} elseif ($targetType -eq "Host") {
    $hostName = Read-Host "Enter the name of the Standalone Host"
    $vmhosts = Get-VMHost -Name $hostName
} else {
    Write-Host "Invalid input. Please enter 'Cluster' or 'Host'."
    exit
}

# Check if any hosts were found
if ($vmhosts.Count -eq 0) {
    Write-Host "No hosts found for the specified target."
    exit
}

# Prompt user for desired power policy
$powerPolicy = Read-Host "Enter the power policy (High Performance, Balanced, Low Power)"
$policyCode = Get-PowerPolicyCode -policy $powerPolicy

# Loop through each host and set the power management policy
foreach ($vmHost in $vmHosts) {
    $view = (Get-VMHost $vmHost | Get-View)
    (Get-View $view.ConfigManager.PowerSystem).ConfigurePowerPolicy($policyCode)

    Write-Host "Power policy for host $($vmHost.Name) set to $powerPolicy."
}
</pre>
<p> </p>]]></content:encoded>
						                            <category domain="https://www.virtualizationhowto.com/community/vmware-vsphere-help/">VMware vSphere help</category>                        <dc:creator>Brandon Lee</dc:creator>
                        <guid isPermaLink="true">https://www.virtualizationhowto.com/community/vmware-vsphere-help/powercli-script-to-change-power-management-active-policy-on-standalone-host-or-cluster/#post-951</guid>
                    </item>
							        </channel>
        </rss>
		