<#
.SYNOPSIS
Creates and activates a "Maximum Performance" power plan with tuned settings.
.DESCRIPTION
Duplicates the hidden Ultimate Performance scheme (falls back to High Performance
if Ultimate is not available on this edition), renames it, applies performance
tuning, and sets it active. Run from an elevated PowerShell prompt.
.PARAMETER IncludeBattery
Also apply performance values on battery (DC). Off by default to protect laptop battery life.
.PARAMETER MonitorTimeoutMinutes
Display off timeout on AC. Does not affect performance. Default 15. Use 0 for never.
.PARAMETER DisableHibernate
Turns hibernation off completely (removes hiberfil.sys and Fast Startup).
.PARAMETER Revert
Switches back to Balanced and deletes the Maximum Performance plan.
.EXAMPLE
.\Set-MaxPerformance.ps1
.\Set-MaxPerformance.ps1 -IncludeBattery -DisableHibernate
.\Set-MaxPerformance.ps1 -Revert
#>
[CmdletBinding()]
param(
[switch]$IncludeBattery,
[int]$MonitorTimeoutMinutes=15,
[switch]$DisableHibernate,
[switch]$Revert
)
$ErrorActionPreference='Stop'$PlanName='Maximum Performance'$UltimateGuid='e9a42b02-d5df-448d-aa00-03f14749eb61'$HighPerfGuid='8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c'$BalancedGuid='381b4222-f694-41f0-9685-ff5bb260df2e'# --- Admin check ---------------------------------------------------------------$principal=New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
if (-not$principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Error'Run this script from an elevated (Administrator) PowerShell prompt.'exit1
}
# --- Helpers -------------------------------------------------------------------functionGet-PlanGuidByName([string]$Name) {
$line= powercfg /list |Where-Object { $_-match[regex]::Escape("($Name)") } |Select-Object-First1if ($line-match'([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})') { return$Matches[1] }
return$null
}
functionSet-PowerValue([string]$Plan, [string]$Sub, [string]$Setting, [int]$Value, [string]$Label) {
powercfg /setacvalueindex $Plan$Sub$Setting$Value2>&1|Out-Null$acOk= ($LASTEXITCODE-eq0)
if ($IncludeBattery) {
powercfg /setdcvalueindex $Plan$Sub$Setting$Value2>&1|Out-Null
}
if ($acOk) { Write-Host (" [OK] {0} = {1}"-f$Label, $Value) -ForegroundColor Green }
else { Write-Host (" [SKIP] {0} (not supported on this hardware)"-f$Label) -ForegroundColor Yellow }
}
# --- Revert --------------------------------------------------------------------if ($Revert) {
powercfg /setactive $BalancedGuid$existing=Get-PlanGuidByName$PlanNameif ($existing) { powercfg /delete $existing;Write-Host"Deleted plan '$PlanName'." }
Write-Host'Balanced plan is active again.'-ForegroundColor Cyan
exit0
}
# --- Remove previous copy so the script is safe to rerun -------------------------$existing=Get-PlanGuidByName$PlanNameif ($existing) {
powercfg /setactive $BalancedGuid
powercfg /delete $existingWrite-Host"Removed previous '$PlanName' plan."
}
# --- Create plan -----------------------------------------------------------------$out= powercfg /duplicatescheme $UltimateGuid2>&1if ($LASTEXITCODE-ne0-or-not ($out-match'([0-9a-fA-F-]{36})')) {
Write-Host'Ultimate Performance not available, using High Performance as base.'-ForegroundColor Yellow
$out= powercfg /duplicatescheme $HighPerfGuid2>&1if (-not ($out-match'([0-9a-fA-F-]{36})')) { Write-Error"Could not duplicate a base scheme: $out";exit1 }
}
$Plan=$Matches[1]
powercfg /changename $Plan$PlanName'Tuned for maximum performance'Write-Host"Created '$PlanName' ($Plan)"-ForegroundColor Cyan
Write-Host'Applying settings:'# --- Processor -------------------------------------------------------------------Set-PowerValue$Plan SUB_PROCESSOR PROCTHROTTLEMIN 100'CPU minimum state (%)'Set-PowerValue$Plan SUB_PROCESSOR PROCTHROTTLEMAX 100'CPU maximum state (%)'Set-PowerValue$Plan SUB_PROCESSOR PERFBOOSTMODE 2'Turbo boost mode (2 = Aggressive)'Set-PowerValue$Plan SUB_PROCESSOR CPMINCORES 100'Core parking min cores (%)'Set-PowerValue$Plan SUB_PROCESSOR PERFEPP 0'Energy performance preference (0 = performance)'# --- Storage, PCIe, USB, Wi-Fi ---------------------------------------------------Set-PowerValue$Plan SUB_DISK DISKIDLE 0'Hard disk turn off after (0 = never)'Set-PowerValue$Plan SUB_PCIEXPRESS ASPM 0'PCIe link state power management (0 = off)'Set-PowerValue$Plan 2a737441-1930-4402-8d77-b2bebba308a3 48e6b7a6-50f5-4782-a5d4-53bb8f07e226 0'USB selective suspend (0 = disabled)'Set-PowerValue$Plan 19cbb8fa-5279-450e-9fac-8a3d5fedd0c1 12bbebe6-58d6-4636-95bb-3217ef867c1a 0'Wireless adapter (0 = max performance)'# --- Sleep and display -----------------------------------------------------------Set-PowerValue$Plan SUB_SLEEP STANDBYIDLE 0'Sleep after (0 = never)'Set-PowerValue$Plan SUB_SLEEP HIBERNATEIDLE 0'Hibernate after (0 = never)'Set-PowerValue$Plan SUB_VIDEO VIDEOIDLE ($MonitorTimeoutMinutes*60) 'Display off after (seconds)'# --- Activate --------------------------------------------------------------------
powercfg /setactive $Planif ($DisableHibernate) {
powercfg /hibernate off
Write-Host' [OK] Hibernation disabled'-ForegroundColor Green
}
Write-Host''Write-Host'Active plan:'-ForegroundColor Cyan
powercfg /getactivescheme
if (-not$IncludeBattery) { Write-Host'Note: battery (DC) values left at plan defaults. Use -IncludeBattery to change them.' }
0 comments