mrk
mrk

Reputation: 1

Create high performance power plan based on existing HP power plan with Powershell

I have a Powershell script I'm working on to automate some processes of our deployment method for a Windows 10 migration. Part of this script activates the High Performance power plan option using powercfg. It works fine on the desktops we use where the three normal plans (Balanced/HP/Power Saver) are already present/created, but the laptops I'm testing it on only have Balanced present in the "Choose power plan" menu.

Usually I'd click through the GUI to "Create power plan" which asks me if I want to base it off an existing plan. Here I'm able to click the High Performance plan template, then just name it as High Performance and use it that way. I'm looking for a way to do this in the Powershell script so I can run this script on both laptops and desktops alike.

Here's what I have for changing the power plan to High Performance on machines where the HP power plan is already created and in the "Choose..." menu (courtesy of SQL Soldier):

Try {
    $HighPerf = powercfg -l | %{if($_.contains("High performance")) {$_.split()[3]}}

    $CurrPlan = $(powercfg -getactivescheme).split()[3]

    if ($CurrPlan -ne $HighPerf) {powercfg -setactive $HighPerf}
        Write-Host "Power plan has been configured to High performance."
} 
Catch {
    Write-Warning -Message "Unable to set power plan to high performance"
}

I have a variable called $Laptop that when -eq to "y" or "Yes" I perform other actions in the script, so I'd like to wrap this code in an if statement based on $Laptop that would create the power plan then activate it if the machine is a laptop, and perform the above code normally if not. I realize this code isn't exactly ironclad, but we only really a select few models so I'm not trying to make it foolproof.

Please let me know if I can clarify anything.

Upvotes: 0

Views: 581

Answers (0)

Related Questions