Files
winutil/functions/public/Invoke-WPFUltimatePerformance.ps1
T

54 lines
2.0 KiB
PowerShell
Raw Normal View History

+3
2023-03-07 12:28:00 -08:00
Function Invoke-WPFUltimatePerformance {
<#
2023-10-19 17:12:55 -05:00
.SYNOPSIS
Creates or removes the Ultimate Performance power scheme
.PARAMETER State
Indicates whether to enable or disable the Ultimate Performance power scheme
+3
2023-03-07 12:28:00 -08:00
#>
param($State)
try {
2024-07-08 22:22:26 +02:00
# Check if Ultimate Performance plan is installed
$ultimatePlan = powercfg -list | Select-String -Pattern "Ultimate Performance"
if($state -eq "Enable") {
2024-07-08 22:22:26 +02:00
if ($ultimatePlan) {
Write-Host "Ultimate Performance plan is already installed."
} else {
Write-Host "Installing Ultimate Performance plan..."
powercfg -duplicatescheme e9a42b02-d5df-448d-aa00-03f14749eb61
Write-Host "> Ultimate Performance plan installed."
2023-10-19 17:12:55 -05:00
}
2023-05-16 14:52:11 -05:00
2024-07-08 22:22:26 +02:00
# Set the Ultimate Performance plan as active
$ultimatePlanGUID = (powercfg -list | Select-String -Pattern "Ultimate Performance").Line.Split()[3]
powercfg -setactive $ultimatePlanGUID
2023-10-19 17:12:55 -05:00
2024-07-08 22:22:26 +02:00
Write-Host "Ultimate Performance plan is now active."
2023-10-19 17:12:55 -05:00
2023-05-16 14:52:11 -05:00
2024-07-08 22:22:26 +02:00
}
elseif($state -eq "Disable") {
2024-07-08 22:22:26 +02:00
if ($ultimatePlan) {
# Extract the GUID of the Ultimate Performance plan
$ultimatePlanGUID = $ultimatePlan.Line.Split()[3]
2024-07-16 21:02:31 +02:00
2024-07-08 22:22:26 +02:00
# Set a different power plan as active before deleting the Ultimate Performance plan
$balancedPlanGUID = (powercfg -list | Select-String -Pattern "Balanced").Line.Split()[3]
powercfg -setactive $balancedPlanGUID
# Delete the Ultimate Performance plan
powercfg -delete $ultimatePlanGUID
Write-Host "Ultimate Performance plan has been uninstalled."
Write-Host "> Balanced plan is now active."
} else {
Write-Host "Ultimate Performance plan is not installed."
2023-05-16 14:52:11 -05:00
}
2024-07-08 22:22:26 +02:00
}
} catch {
+3
2023-03-07 12:28:00 -08:00
Write-Warning $psitem.Exception.Message
}
}