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”
For the import to be effective I added a couple of lines to the capture:
# Write GUID of Saved Power Config to File for Restore Script
Set-Content -Path $env:SystemDrive\$env:COMPUTERNAME.PowerGUID.txt $currentPowerSettings
Then modified the Import as follows:
# Import Power Config
Start-Process “POWERCFG” -ArgumentList “/IMPORT $env:SystemDrive\$env:COMPUTERNAME.pow” -Wait -WindowStyle Hidden
# Retrieve saved GUID of Power Config
$powerGUID = Get-Content “$env:SystemDrive\$env:COMPUTERNAME.PowerGUID.txt”
# Set Imported Power Config Active
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
The above modifications set the imported/saved configuration as the Active Scheme
The /SETACTIVE switch would indeed need to be set for this to become the active policy. Thanks for the suggestion, I’ll amend my original post to include this.
Thanks Paul!