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

SetPowerPlan.ps1:

param($PreferredPlan)

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

Backup.ps1:

...
& 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

TitleDate
Vault 3 Security EnhancementsOctober 24, 2023
Vault 3 is now available for Apple OSX M2 Mac Computers!September 18, 2023
Vault (for Desktop) Version 0.77 ReleasedMarch 26, 2023
EBTCalc (Android) Version 1.44 is now availableOctober 12, 2021
Vault (Desktop) Version 0.72 ReleasedOctober 6, 2021
EBT Compass is Now Available for Android DevicesJune 2, 2021
Convert a Windows 10 Notebook into a High-Capacity Photo FrameApril 3, 2021