How to configure Power Options in Windows (PowerShell)
Introduction
This PowerShell script shows how to use PowerShell module to configure power options.
Scenarios
Most organizations have a number of physical servers and you can make an impact by configuring the power plans on those systems. The appropriate power plan settings can reduce power consumption. We can use this PowerShell module to easily manage the computers' power options.
Script
Step1: To import modules into the Windows PowerShell session, type the command: Import-Module <Script Module Path> at the prompt.
For example, type Import-Module C:\Script\ConfigurePowerOptions
This is shown in the following figure.

Step2: When the script module finishes loading, you can type the Get-Module cmdlet to find the modules that have already been imported into your current session. You can find the modules as shown in the following figure.

Step3: Then, you can use the Get-Command cmdlet to find all available commands. To find all available cmdlets in a module, type Get-Command -Module <module-name>. You can refer to the following figure.

Step4: As you can see, this script module contains four cmdlets. You can use the command Get-Help <cmdlets name> -Full to display the entire help for this function, such as the syntax, parameters, or examples.
For example, type Get-Help Get-PowerPlan -Full as shown in the following figure.

Here are some code snippets for your reference.
If($IsExistPowerPlanError.Exception -eq $null)
{
Write-Verbose "Change the power plan from $CurrentPowerPlan to Power Saver."
$Result = Get-WmiObject -Namespace 'root\cimv2\power' -Class Win32_PowerPlan -Filter "ElementName='$PowerPlan'"`
-ComputerName $ComputerName -EnableAllPrivileges | Invoke-WmiMethod -Name Activate | Select -ExpandProperty ReturnValue
If($Result)
{
Write-Host "Successfully change the power plan in Windows '$ComputerName'."
}
Else
{
Write-Host "Failed to chang the power plan in Windows '$ComputerName'."
}
}
Else
{
Write-Warning "The parameter value was not found, please input the correct parameter value."
}
If($IsExistPowerPlanError.Exception -eq $null) { Write-Verbose"Change the power plan from $CurrentPowerPlan to Power Saver."$Result = Get-WmiObject-Namespace 'root\cimv2\power'-Class Win32_PowerPlan -Filter"ElementName='$PowerPlan'"` -ComputerName $ComputerName-EnableAllPrivileges | Invoke-WmiMethod -Name Activate |Select-ExpandProperty ReturnValue If($Result) { Write-Host "Successfully change the power plan in Windows '$ComputerName'." } Else { Write-Host "Failed to chang the power plan in Windows '$ComputerName'." } } Else { Write-Warning"The parameter value was not found, please input the correct parameter value." }
Prerequisite
Windows PowerShell 3.0
Windows 8