Skip to content

Commit

Permalink
Setting to High Performance Power Profile (#2280)
Browse files Browse the repository at this point in the history
This is to address windows 11 falling sleep
  • Loading branch information
bkatyl authored Mar 4, 2024
1 parent f634db5 commit 6d53a48
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions daisy_workflows/image_build/windows/post_install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,25 @@ function Configure-Network {
Run-Command reg unload 'HKLM\DefaultUser'
}

function Configure-Power {
function Set-PowerProfile {
<#
.SYNOPSIS
Change power plan to High-performance.
#>
Write-Host 'Changing power plan to High performance'
$power_plan = Get-CimInstance -Namespace 'root\cimv2\power' -ClassName 'win32_PowerPlan' -OperationTimeoutSec 5 -Filter "ElementName = 'High performance'" -ErrorAction SilentlyContinue
powercfg /setactive $power_plan.InstanceID.ToString().Replace("Microsoft:PowerPlan\{","").Replace("}","")

$active_plan = powercfg /getactivescheme
if ($active_plan -like '*High performance*') {
Write-Host 'Power plan updated successfully'
}
else {
throw 'Failed to update the power plan'
}
}

function Configure-PowerProfiles {
<#
.SYNOPSIS
Change power settings to never turn off monitor.
Expand Down Expand Up @@ -627,6 +645,9 @@ try {
$script:wu_server_url = Get-MetadataValue -key 'wu_server_url' -default 'none'
$script:wu_server_port = Get-MetadataValue -key 'wu_server_port' -default '0'

# Set to High Performance Power Profile so the machines never go to sleep on their own.
Set-PowerProfile

# Windows Product Name https://renenyffenegger.ch/notes/Windows/versions/index
$pn = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name ProductName).ProductName

Expand Down Expand Up @@ -657,7 +678,7 @@ try {
Reset-WindowsUpdateServer
Change-InstanceProperties
Configure-Network
Configure-Power
Configure-PowerProfiles
Configure-RDP
Setup-NTP

Expand Down

0 comments on commit 6d53a48

Please sign in to comment.