Eric Bergman-Terrell's Blog

PowerShell Tip: Using PowerShell to Change the Power Plan
June 26, 2014

I am running my new notebook computer with the following power plan, which specifies that the machine shuts down after one hour of idleness:

Shut down after 1 hour of inactivity

However, I do not want the machine powering-down when a long-running backup is running. To solve this problem:

  1. I created a new "always on" power plan named "Custom_Always_On".
  2. I updated the backup PowerShell script to switch to the "Custom_Always_On" power plan during the backup, and switch back to the "Custom_Auto_Power_Down" plan when the backup finishes. I found the code on Aaron Saikovski's Technical Blog.

Switch to different Power Plan during Backup



function SetPowerPlan([string]$PreferredPlan)
    Write-Host "Setting Powerplan to $PreferredPlan"
    $guid = (Get-WmiObject -Class win32_powerplan -Namespace root\cimv2\power -Filter "ElementName='$PreferredPlan'").InstanceID.tostring()
    $regex = [regex]"{(.*?)}$"
    $newpowerVal = $regex.Match($guid).groups[1].value

    # setting power setting to high performance
    powercfg -S  $newpowerVal

SetPowerPlan $PreferredPlan


& C:\PSScripts\SetPowerPlan.ps1 "Custom_Always_On"
# code for potentially long-running backup
& C:\PSScripts\SetPowerPlan.ps1 "Custom_Auto_Power_Down"

Now there is no risk of the machine powering-down in the middle of a long backup.

power plan

Use PowerShell to control your computer's power utilization

Keywords: PowerShell, Windows 8.1, Power Plan

Reader Comments

Comment on this Blog Post

Recent Posts

How to decompile Java code with JetBrains IntelliJ IDEA (2018.2.3, Windows 10)October 5, 2018
Java Programming Tip: SWT Photo Frame ProgramOctober 31, 2016
Vault 3 (Desktop) Version 1.63 ReleasedSeptember 9, 2016
"Compliance with Court Orders Act of 2016"April 9, 2016
Disable "Visual Voicemail" on Android / T-MobileJanuary 17, 2016
IPv6 HumorDecember 10, 2015
Java Programming Tip: Specify the JVM time zoneDecember 7, 2015