Capture and Restore Active Power Configuration

I wrote this script to run during an operating system upgrade, you can capture the current Power Config and store it to the system drive.

# Capture Active Power Scheme GUID
$currentPowerSettings = POWERCFG /GETACTIVESCHEME

# Sanitize the variable to just the GUID
$currentPowerSettings = $currentPowerSettings -replace "Power Scheme GUID: ",""
$currentPowerSettings = $currentPowerSettings -replace "  (.*)",""

# Write GUID of Saved Power Config to File for Restore Script
Set-Content -Path $env:SystemDrive\$env:COMPUTERNAME.PowerGUID.txt $currentPowerSettings

# Export to the root of the System Drive with the active GUID.
Start-Process "POWERCFG" -ArgumentList "/EXPORT $env:SystemDrive\$env:COMPUTERNAME.pow $currentPowerSettings" -Wait -WindowStyle Hidden

Then after the system has upgraded, you can run the following command to restore the Power Config.

# Retrieve saved GUID of Power Config
$powerGUID = Get-Content "$env:SystemDrive\$env:COMPUTERNAME.PowerGUID.txt"

# Import and Set the Power Config to Active
Start-Process "POWERCFG" -ArgumentList "/IMPORT $env:SystemDrive\$env:COMPUTERNAME.pow" -Wait -WindowStyle Hidden
Start-Process "POWERCFG" -ArgumentList "/SETACTIVE $powerGUID" -Wait -WindowStyle Hidden

# Cleanup Power Config
Remove-Item "$env:SystemDrive\$env:COMPUTERNAME.pow" -Force
Remove-Item "$env:SystemDrive\$env:COMPUTERNAME.PowerGUID.txt" -Force

If you use SCCM, this can be added as a PowerShell script before and after the upgrade step.

2 Replies to “Capture and Restore Active Power Configuration”

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.