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
$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
try {
$duplicateOutput | Out-File -FilePath $guidFilePath -Append -Encoding utf8 -Force
$guid = $null
$nameFromFile = "ChrisTitus - Ultimate Power Plan"
$description = "Ultimate Power Plan, added via WinUtils"
Write-Output "The output of 'powercfg /duplicatescheme' has been added to $guidFilePath."
} catch {
Write-Error "Error writing to the file: $_"
}
$content = Get-Content -Path $guidFilePath -Encoding utf8
# Extract the GUID from the content
foreach ($line in $content) {
# Extract the GUID directly from the duplicateOutput
foreach ($line in $duplicateOutput) {
if ($line -match "GUID du mode de gestion de l'alimentation\s*:\s*([a-fA-F0-9\-]+)") {
$guid = $matches[1]
# Write the GUID to guid.txt (overwrite existing content)
$guid | Out-File -FilePath $guidFilePath -Encoding utf8 -Force
Write-Output "GUID: $guid has been saved to $guidFilePath"
Write-Output "GUID: $guid has been extracted and stored in the variable."
break
}
}
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
@ -53,7 +35,7 @@ try {
Write-Output "The power plan has been set as active. Output:"
Write-Output $setActiveOutput
} 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 {
Write-Error "Error executing powercfg commands: $_"