Monday, May 18, 2015

PowerShell - Detect/Change/Activate Power Plans

Detect Computer power plans
gwmi -NS root\cimv2\power -Class win32_PowerPlan | select ElementName, IsActive | ft -a

Change/Activate power plan
 - Method 1: Using the CIM cmdlets
$powerplan = Get-CimInstance -Name root\cimv2\power -Class win32_PowerPlan -Filter "ElementName = 'High Performance'"
Invoke-CimMethod -InputObject $powerplan -MethodName Activate
$powerplan = Get-CimInstance -Name root\cimv2\power -Class win32_PowerPlan -Filter "ElementName = 'Power Saver'"
Invoke-CimMethod -InputObject $powerplan -MethodName Activate
 - Method 2: Using Get-WmiObject
$powerplan = gwmi -NS root\cimv2\power -Class win32_PowerPlan -Filter "ElementName ='High Performance'"
$powerplan.Activate()
$powerplan = gwmi -NS root\cimv2\power -Class win32_PowerPlan -Filter "ElementName ='Power Saver'"
$powerplan.Activate()

Turn Off Hard Drive Sleep
powercfg -CHANGE -disk-timeout-ac 0