Add scripts for backing up energy plan

This commit is contained in:
Manuel Thalmann 2024-09-21 02:10:20 +02:00
parent 15e725ffaf
commit 3dcf228ca7
3 changed files with 60 additions and 1 deletions

View file

@ -83,6 +83,7 @@ $null = New-Module {
if ($IsWindows) { if ($IsWindows) {
$env:WSLENV = "CONFIG_NAME"; $env:WSLENV = "CONFIG_NAME";
New-Alias -Force "sudo" gsudo; New-Alias -Force "sudo" gsudo;
Backup-PowerScheme;
} }
if (-not $NoImplicitCleanup.IsPresent) { if (-not $NoImplicitCleanup.IsPresent) {
@ -418,6 +419,7 @@ $null = New-Module {
$null = Uninstall-Package Selenium.WebDriver -ErrorAction Continue; $null = Uninstall-Package Selenium.WebDriver -ErrorAction Continue;
Uninstall-ChocoPackage 7zip.portable gsudo selenium-gecko-driver yq; Uninstall-ChocoPackage 7zip.portable gsudo selenium-gecko-driver yq;
Uninstall-WingetPackage AutoHotkey.AutoHotkey; Uninstall-WingetPackage AutoHotkey.AutoHotkey;
Restore-PowerScheme;
} }
foreach ($module in (Get-RequiredModules)) { foreach ($module in (Get-RequiredModules)) {

View file

@ -1,3 +1,4 @@
. "$PSScriptRoot/PowerManagement.ps1";
. "$PSScriptRoot/../../Common/Scripts/Software.ps1"; . "$PSScriptRoot/../../Common/Scripts/Software.ps1";
. "$PSScriptRoot/../../Common/Scripts/SoftwareManagement.ps1"; . "$PSScriptRoot/../../Common/Scripts/SoftwareManagement.ps1";
. "$PSScriptRoot/../../Common/Types/InstallerAction.ps1"; . "$PSScriptRoot/../../Common/Types/InstallerAction.ps1";
@ -61,7 +62,12 @@ function Deploy-SoftwareAction {
if ($install) { if ($install) {
if ($hardware.amdCPU) { if ($hardware.amdCPU) {
Install-ChocoPackage amd-ryzen-master; Install-ChocoPackage amd-ryzen-master;
# ToDo: backup Ryzen energy saving plan $ryzenPlan = [regex]::Match("" + ((powercfg /LIST) | Where-Object { $_ -like "*(AMD Ryzen*"; }), "Power Scheme GUID: ([0-9a-f-]+) ").Groups[1].Value;
if ($ryzenPlan) {
powercfg /S $ryzenPlan;
Backup-PowerScheme;
}
} }
if ($hardware.nvidiaGPU) { if ($hardware.nvidiaGPU) {

View file

@ -9,6 +9,7 @@ $null = New-Module {
$systemRunOncePath = "HKLM:\$runOncePath"; $systemRunOncePath = "HKLM:\$runOncePath";
$logonPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" $logonPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
$runOnceName = "PortValhalla"; $runOnceName = "PortValhalla";
$powerSchemeOption = "PowerScheme";
$autologinOption = "AutoAdminLogon"; $autologinOption = "AutoAdminLogon";
$domainOption = "DefaultDomainName"; $domainOption = "DefaultDomainName";
$userOption = "DefaultUserName"; $userOption = "DefaultUserName";
@ -59,6 +60,56 @@ $null = New-Module {
"& `$env:INSTALLER_SCRIPT;"; "& `$env:INSTALLER_SCRIPT;";
} }
<#
.SYNOPSIS
Gets the GUID of the current power scheme.
#>
function Get-PowerScheme {
[regex]::Match((powercfg /GETACTIVESCHEME), "Power Scheme GUID: ([0-9a-f-]+) ").Groups[1].Value;
}
<#
.SYNOPSIS
Sets the current power scheme.
.PARAMETER SchemeID
The ID of the scheme to set.
#>
function Set-PowerScheme {
param(
[string] $SchemeID
)
powercfg /S $SchemeID;
}
<#
.SYNOPSIS
Backs up and overrides the current power scheme if it might cause automatic standby.
#>
function Backup-PowerScheme {
$performanceScheme = "8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c";
$currentScheme = Get-PowerScheme;
if ($currentScheme -ne $performanceScheme) {
Write-Host "Disabling Power Save mode";
Set-SetupOption $powerSchemeOption $currentScheme;
powercfg /S $performanceScheme;
}
}
<#
.SYNOPSIS
Restores the backed up power scheme.
#>
function Restore-PowerScheme {
$scheme = Get-SetupOption $powerSchemeOption;
if ($scheme) {
powercfg /S $scheme;
}
}
<# <#
.SYNOPSIS .SYNOPSIS
Registers a task to run the setup once after the next reboot. Registers a task to run the setup once after the next reboot.