Created
January 22, 2020 01:10
-
-
Save jennings/2f4e66e3c9eaa7270ad1c0a46683a830 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Caffeinate { | |
param([scriptblock]$ScriptBlock) | |
$active_scheme_id = (powercfg /GetActiveScheme).Split(" ")[3] | |
$high_perf_id = "8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c" | |
powercfg /s $high_perf_id | |
if ($LASTEXITCODE -ne 0) { return } | |
try { | |
& $ScriptBlock | |
} finally { | |
powercfg /s $active_scheme_id | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment