Removed the GUID.txt for a local variable

This commit is contained in:
Atis 2024-08-11 05:39:05 +02:00 committed by GitHub
parent 09fed571b7
commit 71173740ae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,43 +1,25 @@
# PowerShell script to fix the power plan applied across all languages based on the GUID of the new power plan.
# This is necessary because when Windows is in a different language, the power plan might not be applied correctly.
# This script changes the name and description of the power plan.
#Video : https://youtu.be/00aUECZNvbA
# ID of the plan to duplicate # ID of the plan to duplicate
$sourceGUID = "e9a42b02-d5df-448d-aa00-03f14749eb61" $sourceGUID = "e9a42b02-d5df-448d-aa00-03f14749eb61"
$guid = $null
$nameFromFile = "ChrisTitus - Ultimate Power Plan"
$description = "Ultimate Power Plan , added via WinUtils"
$scriptPath = $MyInvocation.MyCommand.Path
$directoryPath = Split-Path -Path $scriptPath -Parent
$guidFilePath = Join-Path -Path $directoryPath -ChildPath "guid.txt"
# Duplicate the power plan
$duplicateOutput = powercfg /duplicatescheme $sourceGUID $duplicateOutput = powercfg /duplicatescheme $sourceGUID
try { $guid = $null
$duplicateOutput | Out-File -FilePath $guidFilePath -Append -Encoding utf8 -Force $nameFromFile = "ChrisTitus - Ultimate Power Plan"
$description = "Ultimate Power Plan, added via WinUtils"
Write-Output "The output of 'powercfg /duplicatescheme' has been added to $guidFilePath." # Extract the GUID directly from the duplicateOutput
} catch { foreach ($line in $duplicateOutput) {
Write-Error "Error writing to the file: $_"
}
$content = Get-Content -Path $guidFilePath -Encoding utf8
# Extract the GUID from the content
foreach ($line in $content) {
if ($line -match "GUID du mode de gestion de l'alimentation\s*:\s*([a-fA-F0-9\-]+)") { if ($line -match "GUID du mode de gestion de l'alimentation\s*:\s*([a-fA-F0-9\-]+)") {
$guid = $matches[1] $guid = $matches[1]
# Write the GUID to guid.txt (overwrite existing content) Write-Output "GUID: $guid has been extracted and stored in the variable."
$guid | Out-File -FilePath $guidFilePath -Encoding utf8 -Force break
Write-Output "GUID: $guid has been saved to $guidFilePath"
} }
} }
if (-not $guid) { if (-not $guid) {
Write-Output "No GUID found in $guidFilePath. Check the content format." Write-Output "No GUID found in the duplicateOutput. Check the output format."
exit 1
} }
# Execute commands to change the plan name and set the plan as active # Execute commands to change the plan name and set the plan as active
@ -53,7 +35,7 @@ try {
Write-Output "The power plan has been set as active. Output:" Write-Output "The power plan has been set as active. Output:"
Write-Output $setActiveOutput Write-Output $setActiveOutput
} else { } else {
Write-Output "GUID is missing. Ensure that guid.txt contains the necessary information." Write-Output "GUID is missing. Ensure that the GUID was properly extracted."
} }
} catch { } catch {
Write-Error "Error executing powercfg commands: $_" Write-Error "Error executing powercfg commands: $_"