From 29ce6aeeaf5d81949e21e141f7b89e15ed87d03c Mon Sep 17 00:00:00 2001 From: Bob Tanner Date: Mon, 13 Nov 2017 21:09:41 -0600 Subject: [PATCH] WIP https://github.com/StefanScherer/packer-windows/issues/49 Make sure we find a High Performance power profile before blindly setting the power profile. --- scripts/set-powerplan.ps1 | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/scripts/set-powerplan.ps1 b/scripts/set-powerplan.ps1 index 65ee32c1..646eba74 100644 --- a/scripts/set-powerplan.ps1 +++ b/scripts/set-powerplan.ps1 @@ -1,7 +1,20 @@ Try { + Write-Output "Set power plan to high performance" + $HighPerf = powercfg -l | %{if($_.contains("High performance")) {$_.split()[3]}} + + # $HighPerf cannot be $null, we try activate this power profile with powercfg + # + if ($HighPerf -eq $null) + { + throw "Error: HighPerf is null" + } + $CurrPlan = $(powercfg -getactivescheme).split()[3] + if ($CurrPlan -ne $HighPerf) {powercfg -setactive $HighPerf} + } Catch { Write-Warning -Message "Unable to set power plan to high performance" + Write-Warning $Error[0] }