Changing Power Options with Powershell












0















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:tempSet-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:tempSet-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)
{
$result
}
}
else
{
Write-Error (“The requested power scheme ‘{0}’ does not exist on this machine” -f $Plan)
}









share|improve this question

























  • 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


















0















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:tempSet-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:tempSet-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)
{
$result
}
}
else
{
Write-Error (“The requested power scheme ‘{0}’ does not exist on this machine” -f $Plan)
}









share|improve this question

























  • 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
















0












0








0








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:tempSet-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:tempSet-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)
{
$result
}
}
else
{
Write-Error (“The requested power scheme ‘{0}’ does not exist on this machine” -f $Plan)
}









share|improve this question
















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:tempSet-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:tempSet-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)
{
$result
}
}
else
{
Write-Error (“The requested power scheme ‘{0}’ does not exist on this machine” -f $Plan)
}






powershell script shell-script power-management






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 14 '18 at 19:49









Ahmed Ashour

1,144611




1,144611










asked Dec 14 '18 at 15:55









JamesJames

184




184













  • 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





















  • 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



















What script are you running exactly?

– Ramhound
Dec 14 '18 at 17:09





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





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





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







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







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












1 Answer
1






active

oldest

votes


















0














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 rootcimv2power -Class win32_PowerPlan | select ElementName,
IsActive | ft -a

$p = gwmi -NS rootcimv2power -Class win32_PowerPlan -Filter "ElementName ='Ultimate
Performance'"

$p.Activate()


Get-CimInstance -N rootcimv2power -Class win32_PowerPlan | select ElementName,
IsActive | ft -a

pause





share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "3"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1383627%2fchanging-power-options-with-powershell%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    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 rootcimv2power -Class win32_PowerPlan | select ElementName,
    IsActive | ft -a

    $p = gwmi -NS rootcimv2power -Class win32_PowerPlan -Filter "ElementName ='Ultimate
    Performance'"

    $p.Activate()


    Get-CimInstance -N rootcimv2power -Class win32_PowerPlan | select ElementName,
    IsActive | ft -a

    pause





    share|improve this answer




























      0














      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 rootcimv2power -Class win32_PowerPlan | select ElementName,
      IsActive | ft -a

      $p = gwmi -NS rootcimv2power -Class win32_PowerPlan -Filter "ElementName ='Ultimate
      Performance'"

      $p.Activate()


      Get-CimInstance -N rootcimv2power -Class win32_PowerPlan | select ElementName,
      IsActive | ft -a

      pause





      share|improve this answer


























        0












        0








        0







        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 rootcimv2power -Class win32_PowerPlan | select ElementName,
        IsActive | ft -a

        $p = gwmi -NS rootcimv2power -Class win32_PowerPlan -Filter "ElementName ='Ultimate
        Performance'"

        $p.Activate()


        Get-CimInstance -N rootcimv2power -Class win32_PowerPlan | select ElementName,
        IsActive | ft -a

        pause





        share|improve this answer













        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 rootcimv2power -Class win32_PowerPlan | select ElementName,
        IsActive | ft -a

        $p = gwmi -NS rootcimv2power -Class win32_PowerPlan -Filter "ElementName ='Ultimate
        Performance'"

        $p.Activate()


        Get-CimInstance -N rootcimv2power -Class win32_PowerPlan | select ElementName,
        IsActive | ft -a

        pause






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 7 at 18:57









        JamesJames

        184




        184






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Super User!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1383627%2fchanging-power-options-with-powershell%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to reconfigure Docker Trusted Registry 2.x.x to use CEPH FS mount instead of NFS and other traditional...

            is 'sed' thread safe

            How to make a Squid Proxy server?