I am a newbie when it comes to scripting. I am running the script above. I believe I have to take and change this line of code:

{param ($Plan = $(throw ‘Set-PowerPlan Ultimate Performance’ ))}

but I am not sure since I am getting the following error when I run the script in PS:

At C:\temp\Set-PowerPlan.ps1:35 char:67
+ ... RegEx = “(?<planguid>[A-Fa-f0-9]{8}-(?:[A-Fa-f0-9]{4}-){3}[A-Fa-f0- ...
+ ~
Array index expression is missing or not valid.
At C:\temp\Set-PowerPlan.ps1:41 char:36
+ $result = powercfg -s $matches[“PlanGUIDâ€] 2>&1
+ ~
Array index expression is missing or not valid.
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : MissingArrayIndexExpression

The only line of code I changed was the one above.
Yes "Ultimate Performance" power scheme is installed.
Do I need to do anything else?
I am trying to change the Power Options to "Ultimate Performance" this option is already install by a previous command. Script I was running:

param ($Plan = $(throw ‘Set-PowerPlan Ultimate Performance’ ))

Set-StrictMode -Version Latest

# Get the list of plans on the current machine.
$planList = powercfg.exe -l

# The regular expression to pull out the GUID for the specified plan.
$planRegEx = “(?<PlanGUID>[A-Fa-f0-9]{8}-(?:[A-Fa-f0-9]{4}-){3}[A-Fa-f0-9]{12})” + (“(?:s+({0}))” -f $Plan)

# If the plan appears in the list…
if ( ($planList | Out-String) -match $planRegEx )
    # Pull out the matching GUID and capture both stdout and stderr.
    $result = powercfg -s $matches[“PlanGUID”] 2>&1

    # If there were any problems, show the error.
    if ( $LASTEXITCODE -ne 0)
    Write-Error (“The requested power scheme ‘{0}’ does not exist on this machine” -f $Plan)
  • What script are you running exactly? – Ramhound Dec 14 '18 at 17:09
  • Your initial assertion is wrong -- you do not change anything in the param {} block. Re-download the script and run Set-PowerPlan -Plan 'Ultimate Performance' – thepip3r Dec 14 '18 at 17:34
  • I kind of newbie to powershell scripting and i not quite understanding what you are telling me to do? – James Dec 14 '18 at 18:34
  • What did the working version of the script look like? Why wouldn't you just use powercfg.exe to do this? The regular expression is the problem. – Ramhound Dec 14 '18 at 20:05
  • According to the powercfg.exe it uses the GUID to change power schemas in powershell not the name. I need to do this to multiple computer which makes the GUID different on every machine. If i do the script from thepip3r i get this response from Power Shell Set-PowerPlan : The term 'Set-PowerPlan' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + Set-PowerPlan -Plan 'Ultimate Performance' + ~~~~~~~~~~~~~ – James Dec 14 '18 at 20:36

I have figured out how to change the Power Schema by it's name not GUID The following code will change the Power Schema to "Ultimate Performance" but can be used to change it to any of the common names

#Change to Ultimate Performance Power Schema

Get-CimInstance -N root\cimv2\power -Class win32_PowerPlan | select ElementName, 
IsActive | ft -a

$p = gwmi -NS root\cimv2\power -Class win32_PowerPlan -Filter "ElementName ='Ultimate 


Get-CimInstance -N root\cimv2\power -Class win32_PowerPlan | select ElementName, 
IsActive | ft -a


Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.