mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-06-27 16:44:46 -05:00
[Tweaks] Fix Disabling of Ultimate Performance Profile (#3436)
* improve general codequality of function * fix issue with disable process - remove ".Line.Split()[3]" - change $balancedPlanGUID to be in brackets
This commit is contained in:
@ -8,13 +8,18 @@ Function Invoke-WPFUltimatePerformance {
|
|||||||
Specifies whether to "Enable" or "Disable" the Ultimate Performance power scheme.
|
Specifies whether to "Enable" or "Disable" the Ultimate Performance power scheme.
|
||||||
|
|
||||||
#>
|
#>
|
||||||
param($State)
|
param(
|
||||||
|
[Parameter(Mandatory = $true)]
|
||||||
|
[ValidateSet("Enable", "Disable")]
|
||||||
|
[string]$State
|
||||||
|
)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
# GUID of the Ultimate Performance power plan
|
# GUID of the Ultimate Performance power plan
|
||||||
$ultimateGUID = "e9a42b02-d5df-448d-aa00-03f14749eb61"
|
$ultimateGUID = "e9a42b02-d5df-448d-aa00-03f14749eb61"
|
||||||
|
|
||||||
if ($State -eq "Enable") {
|
switch ($State) {
|
||||||
|
"Enable" {
|
||||||
# Duplicate the Ultimate Performance power plan using its GUID
|
# Duplicate the Ultimate Performance power plan using its GUID
|
||||||
$duplicateOutput = powercfg /duplicatescheme $ultimateGUID
|
$duplicateOutput = powercfg /duplicatescheme $ultimateGUID
|
||||||
|
|
||||||
@ -47,17 +52,17 @@ Function Invoke-WPFUltimatePerformance {
|
|||||||
Write-Output $setActiveOutput
|
Write-Output $setActiveOutput
|
||||||
|
|
||||||
Write-Host "> Ultimate Performance plan installed and set as active."
|
Write-Host "> Ultimate Performance plan installed and set as active."
|
||||||
|
}
|
||||||
} elseif ($State -eq "Disable") {
|
"Disable" {
|
||||||
# Check if the Ultimate Performance plan is installed by GUID
|
# Check if the Ultimate Performance plan is installed by GUID
|
||||||
$installedPlan = (powercfg -list | Select-String -Pattern "ChrisTitus - Ultimate Power Plan").Line.Split()[3]
|
$installedPlan = powercfg -list | Select-String -Pattern "ChrisTitus - Ultimate Power Plan"
|
||||||
|
|
||||||
if ($installedPlan) {
|
if ($installedPlan) {
|
||||||
# Extract the GUID of the installed Ultimate Performance plan
|
# Extract the GUID of the installed Ultimate Performance plan
|
||||||
$ultimatePlanGUID = $installedPlan.Line.Split()[3]
|
$ultimatePlanGUID = $installedPlan.Line.Split()[3]
|
||||||
|
|
||||||
# Set a different power plan as active before deleting the Ultimate Performance plan
|
# Set a different power plan as active before deleting the Ultimate Performance plan
|
||||||
$balancedPlanGUID = 381b4222-f694-41f0-9685-ff5bb260df2e
|
$balancedPlanGUID = "381b4222-f694-41f0-9685-ff5bb260df2e"
|
||||||
powercfg -setactive $balancedPlanGUID
|
powercfg -setactive $balancedPlanGUID
|
||||||
|
|
||||||
# Delete the Ultimate Performance plan by GUID
|
# Delete the Ultimate Performance plan by GUID
|
||||||
@ -69,6 +74,10 @@ Function Invoke-WPFUltimatePerformance {
|
|||||||
Write-Host "Ultimate Performance plan is not installed."
|
Write-Host "Ultimate Performance plan is not installed."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
default {
|
||||||
|
Write-Host "Invalid state. Please use 'Enable' or 'Disable'."
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
Write-Error "Error occurred: $_"
|
Write-Error "Error occurred: $_"
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user