mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2024-11-14 06:35:51 -06:00
Fix power profile (#766)
* Fix power profile query * fix syntax * fix * Update Invoke-WPFUltimatePerformance.ps1 * Update winutil.ps1 * power profile fix
This commit is contained in:
parent
6ffca764ef
commit
2c6b459870
@ -7,22 +7,64 @@ Function Invoke-WPFUltimatePerformance {
|
|||||||
#>
|
#>
|
||||||
param($State)
|
param($State)
|
||||||
Try{
|
Try{
|
||||||
$guid = "e9a42b02-d5df-448d-aa00-03f14749eb61"
|
|
||||||
|
|
||||||
if($state -eq "Enabled"){
|
if($state -eq "Enabled"){
|
||||||
Write-Host "Adding Ultimate Performance Profile"
|
# Define the name and GUID of the power scheme you want to add
|
||||||
[scriptblock]$command = {powercfg -duplicatescheme $guid}
|
$powerSchemeName = "Ultimate Performance"
|
||||||
|
$powerSchemeGuid = "e9a42b02-d5df-448d-aa00-03f14749eb61"
|
||||||
|
|
||||||
|
# Get all power schemes
|
||||||
|
$schemes = powercfg /list | Out-String -Stream
|
||||||
|
|
||||||
|
# Find the scheme you want to add
|
||||||
|
$ultimateScheme = $schemes | Where-Object { $_ -match $powerSchemeName }
|
||||||
|
|
||||||
|
# If the scheme does not exist, add it
|
||||||
|
if ($null -eq $ultimateScheme) {
|
||||||
|
Write-Host "Power scheme '$powerSchemeName' not found. Adding..."
|
||||||
|
|
||||||
|
# Add the power scheme
|
||||||
|
powercfg /duplicatescheme $powerSchemeGuid
|
||||||
|
|
||||||
|
Write-Host "Power scheme added successfully."
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Write-Host "Power scheme '$powerSchemeName' already exists."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elseif($state -eq "Disabled"){
|
||||||
|
# Define the name of the power scheme you want to remove
|
||||||
|
$powerSchemeName = "Ultimate Performance"
|
||||||
|
|
||||||
|
# Get all power schemes
|
||||||
|
$schemes = powercfg /list | Out-String -Stream
|
||||||
|
|
||||||
|
# Find the scheme you want to remove
|
||||||
|
$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..."
|
||||||
|
|
||||||
|
# Remove the power scheme
|
||||||
|
powercfg /delete $guid
|
||||||
|
|
||||||
|
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."
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if($state -eq "Disabled"){
|
|
||||||
Write-Host "Removing Ultimate Performance Profile"
|
|
||||||
[scriptblock]$command = {powercfg -delete $guid}
|
|
||||||
}
|
|
||||||
|
|
||||||
$output = Invoke-Command -ScriptBlock $command
|
|
||||||
if($output -like "*does not exist*"){
|
|
||||||
throw [GenericException]::new('Failed to modify profile')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Catch{
|
Catch{
|
||||||
Write-Warning $psitem.Exception.Message
|
Write-Warning $psitem.Exception.Message
|
||||||
|
66
winutil.ps1
66
winutil.ps1
@ -1501,22 +1501,64 @@ Function Invoke-WPFUltimatePerformance {
|
|||||||
#>
|
#>
|
||||||
param($State)
|
param($State)
|
||||||
Try{
|
Try{
|
||||||
$guid = "e9a42b02-d5df-448d-aa00-03f14749eb61"
|
|
||||||
|
|
||||||
if($state -eq "Enabled"){
|
if($state -eq "Enabled"){
|
||||||
Write-Host "Adding Ultimate Performance Profile"
|
# Define the name and GUID of the power scheme you want to add
|
||||||
[scriptblock]$command = {powercfg -duplicatescheme $guid}
|
$powerSchemeName = "Ultimate Performance"
|
||||||
|
$powerSchemeGuid = "e9a42b02-d5df-448d-aa00-03f14749eb61"
|
||||||
|
|
||||||
|
# Get all power schemes
|
||||||
|
$schemes = powercfg /list | Out-String -Stream
|
||||||
|
|
||||||
|
# Find the scheme you want to add
|
||||||
|
$ultimateScheme = $schemes | Where-Object { $_ -match $powerSchemeName }
|
||||||
|
|
||||||
|
# If the scheme does not exist, add it
|
||||||
|
if ($null -eq $ultimateScheme) {
|
||||||
|
Write-Host "Power scheme '$powerSchemeName' not found. Adding..."
|
||||||
|
|
||||||
|
# Add the power scheme
|
||||||
|
powercfg /duplicatescheme $powerSchemeGuid
|
||||||
|
|
||||||
|
Write-Host "Power scheme added successfully."
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Write-Host "Power scheme '$powerSchemeName' already exists."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elseif($state -eq "Disabled"){
|
||||||
|
# Define the name of the power scheme you want to remove
|
||||||
|
$powerSchemeName = "Ultimate Performance"
|
||||||
|
|
||||||
|
# Get all power schemes
|
||||||
|
$schemes = powercfg /list | Out-String -Stream
|
||||||
|
|
||||||
|
# Find the scheme you want to remove
|
||||||
|
$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..."
|
||||||
|
|
||||||
|
# Remove the power scheme
|
||||||
|
powercfg /delete $guid
|
||||||
|
|
||||||
|
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."
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if($state -eq "Disabled"){
|
|
||||||
Write-Host "Removing Ultimate Performance Profile"
|
|
||||||
[scriptblock]$command = {powercfg -delete $guid}
|
|
||||||
}
|
|
||||||
|
|
||||||
$output = Invoke-Command -ScriptBlock $command
|
|
||||||
if($output -like "*does not exist*"){
|
|
||||||
throw [GenericException]::new('Failed to modify profile')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Catch{
|
Catch{
|
||||||
Write-Warning $psitem.Exception.Message
|
Write-Warning $psitem.Exception.Message
|
||||||
@ -5371,7 +5413,7 @@ catch [System.Management.Automation.MethodInvocationException] {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
# If it broke some other way <img draggable="false" role="img" class="emoji" alt="????" src="https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/svg/1f600.svg">
|
# If it broke some other way <img draggable="false" role="img" class="emoji" alt="??" src="https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/svg/1f600.svg">
|
||||||
Write-Host "Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed."
|
Write-Host "Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user