First post for 2012 – Updated Setting the Machine Powerplan using PowerShell
Happy 2012 everyone!
Here is an updated Powershell script for setting the powerplan on a server in a much more efficient manner.
A big shout out to Amir Rothschild - PFE Extraordinaire & Shay Levy - PowerShell MVP – Thanks guys!
Here is the updated PowerShell script:
1: ##############################################################################################################
2: #
3: # Title: Set-Power.ps1
4: #
5: # By: Aaron Saikovski (asaikov)
6: #
7: # Purpose: Sets the powerplan of the current machine to one of three plan settings:
8: # High Performance
9: # Balanced
10: # Power Saver
11: #
12: # Usage: ./Set-Power.ps1 <Plan Option>
13: #
14: # Version: 2.0
15: #
16: # Activation code courtesy to Amir Rothschild (amrotchi) - PFE Extraordinaire & Shay Levy - PowerShell MVP
17: #
18: ##############################################################################################################
19:
20: ##############################################################################################################
21: #
22: # Variables used in this script
23: #
24: # [string]$PreferredPlan # Powerplan to set the machine to
25: #
26: ##############################################################################################################
27:
28: PARAM
29: (
30: [Parameter(Mandatory=$true)][ValidateSet("High performance", "Balanced", "Power saver")]
31: [string]$PreferredPlan
32: )
33:
34: function SetPowerPlan([string]$PreferredPlan)
35: {
36: Write-Host "Setting Powerplan to $PreferredPlan"
37: (Get-WmiObject -Class Win32_PowerPlan -Namespace root\cimv2\power -Filter "ElementName='$PreferredPlan'").Activate()
38: }
39:
40: #set Preferred powerplan
41: SetPowerPlan $PreferredPlan