From 71173740ae3d08badbb626aac6c29f2dd76ed479 Mon Sep 17 00:00:00 2001 From: Atis <94861317+AtisFPS@users.noreply.github.com> Date: Sun, 11 Aug 2024 05:39:05 +0200 Subject: [PATCH] Removed the GUID.txt for a local variable --- utilmatepowerplan-fix.ps1 | 40 +++++++++++---------------------------- 1 file changed, 11 insertions(+), 29 deletions(-) diff --git a/utilmatepowerplan-fix.ps1 b/utilmatepowerplan-fix.ps1 index 3e8cc543..23d8d745 100644 --- a/utilmatepowerplan-fix.ps1 +++ b/utilmatepowerplan-fix.ps1 @@ -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: $_"