Add scripts for backing up energy plan
This commit is contained in:
parent
15e725ffaf
commit
3dcf228ca7
|
@ -83,6 +83,7 @@ $null = New-Module {
|
|||
if ($IsWindows) {
|
||||
$env:WSLENV = "CONFIG_NAME";
|
||||
New-Alias -Force "sudo" gsudo;
|
||||
Backup-PowerScheme;
|
||||
}
|
||||
|
||||
if (-not $NoImplicitCleanup.IsPresent) {
|
||||
|
@ -418,6 +419,7 @@ $null = New-Module {
|
|||
$null = Uninstall-Package Selenium.WebDriver -ErrorAction Continue;
|
||||
Uninstall-ChocoPackage 7zip.portable gsudo selenium-gecko-driver yq;
|
||||
Uninstall-WingetPackage AutoHotkey.AutoHotkey;
|
||||
Restore-PowerScheme;
|
||||
}
|
||||
|
||||
foreach ($module in (Get-RequiredModules)) {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
. "$PSScriptRoot/PowerManagement.ps1";
|
||||
. "$PSScriptRoot/../../Common/Scripts/Software.ps1";
|
||||
. "$PSScriptRoot/../../Common/Scripts/SoftwareManagement.ps1";
|
||||
. "$PSScriptRoot/../../Common/Types/InstallerAction.ps1";
|
||||
|
@ -61,7 +62,12 @@ function Deploy-SoftwareAction {
|
|||
if ($install) {
|
||||
if ($hardware.amdCPU) {
|
||||
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) {
|
||||
|
|
|
@ -9,6 +9,7 @@ $null = New-Module {
|
|||
$systemRunOncePath = "HKLM:\$runOncePath";
|
||||
$logonPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
|
||||
$runOnceName = "PortValhalla";
|
||||
$powerSchemeOption = "PowerScheme";
|
||||
$autologinOption = "AutoAdminLogon";
|
||||
$domainOption = "DefaultDomainName";
|
||||
$userOption = "DefaultUserName";
|
||||
|
@ -59,6 +60,56 @@ $null = New-Module {
|
|||
"& `$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
|
||||
Registers a task to run the setup once after the next reboot.
|
||||
|
|
Loading…
Reference in a new issue