2023-03-07 14:28:00 -06: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
|
|
|
|
|
2023-03-07 14:28:00 -06:00
|
|
|
#>
|
|
|
|
param($State)
|
|
|
|
Try{
|
|
|
|
|
|
|
|
if($state -eq "Enabled"){
|
2023-10-19 17:12:55 -05:00
|
|
|
# Define the name and GUID of the power scheme
|
2023-05-16 14:52:11 -05:00
|
|
|
$powerSchemeName = "Ultimate Performance"
|
|
|
|
$powerSchemeGuid = "e9a42b02-d5df-448d-aa00-03f14749eb61"
|
|
|
|
|
|
|
|
# Get all power schemes
|
|
|
|
$schemes = powercfg /list | Out-String -Stream
|
|
|
|
|
2023-10-19 17:12:55 -05:00
|
|
|
# Check if the power scheme already exists
|
2023-05-16 14:52:11 -05:00
|
|
|
$ultimateScheme = $schemes | Where-Object { $_ -match $powerSchemeName }
|
|
|
|
|
|
|
|
if ($null -eq $ultimateScheme) {
|
|
|
|
Write-Host "Power scheme '$powerSchemeName' not found. Adding..."
|
|
|
|
|
|
|
|
# Add the power scheme
|
|
|
|
powercfg /duplicatescheme $powerSchemeGuid
|
2023-07-15 10:42:11 -05:00
|
|
|
powercfg -attributes SUB_SLEEP 7bc4a2f9-d8fc-4469-b07b-33eb785aaca0 -ATTRIB_HIDE
|
2023-10-19 17:12:55 -05:00
|
|
|
powercfg -setactive $powerSchemeGuid
|
|
|
|
powercfg -change -monitor-timeout-ac 0
|
|
|
|
|
2023-05-16 14:52:11 -05:00
|
|
|
|
|
|
|
Write-Host "Power scheme added successfully."
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Write-Host "Power scheme '$powerSchemeName' already exists."
|
2023-10-19 17:12:55 -05:00
|
|
|
}
|
2023-03-07 14:28:00 -06:00
|
|
|
}
|
2023-05-16 14:52:11 -05:00
|
|
|
elseif($state -eq "Disabled"){
|
2023-10-19 17:12:55 -05:00
|
|
|
# Define the name of the power scheme
|
2023-05-16 14:52:11 -05:00
|
|
|
$powerSchemeName = "Ultimate Performance"
|
|
|
|
|
|
|
|
# Get all power schemes
|
|
|
|
$schemes = powercfg /list | Out-String -Stream
|
|
|
|
|
2023-10-19 17:12:55 -05:00
|
|
|
# Find the scheme to be removed
|
2023-05-16 14:52:11 -05:00
|
|
|
$ultimateScheme = $schemes | Where-Object { $_ -match $powerSchemeName }
|
|
|
|
|
|
|
|
# If the scheme exists, remove it
|
|
|
|
if ($null -ne $ultimateScheme) {
|
|
|
|
# Extract the GUID of the power scheme
|
|
|
|
$guid = ($ultimateScheme -split '\s+')[3]
|
|
|
|
|
|
|
|
if($null -ne $guid){
|
|
|
|
Write-Host "Found power scheme '$powerSchemeName' with GUID $guid. Removing..."
|
2023-10-19 17:12:55 -05:00
|
|
|
|
2023-05-16 14:52:11 -05:00
|
|
|
# Remove the power scheme
|
|
|
|
powercfg /delete $guid
|
2023-10-19 17:12:55 -05:00
|
|
|
|
2023-05-16 14:52:11 -05:00
|
|
|
Write-Host "Power scheme removed successfully."
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Write-Host "Could not find GUID for power scheme '$powerSchemeName'."
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Write-Host "Power scheme '$powerSchemeName' not found."
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-10-19 17:12:55 -05:00
|
|
|
|
2023-03-07 14:28:00 -06:00
|
|
|
}
|
|
|
|
Catch{
|
|
|
|
Write-Warning $psitem.Exception.Message
|
|
|
|
}
|
2023-05-16 14:52:11 -05:00
|
|
|
}
|