Need Help Editing PoSh Script

Hello, everyone. I want to use a PowerShell script to adjust the Power Mode slider in Windows 10 from the default ‘Balanced’ to ‘Best Performance’. I found an existing script that cycles through the 3 power mode options to correct a specific issue. However I would like to massage it to just do a one time change from balanced to best performance. Any help is greatly appreciated!
Here is the existing script:

Toggle power mode away from and then back to effective overlay

$togglePowerOverlay = {
$function = @’
[DllImport(“powrprof.dll”, EntryPoint=“PowerSetActiveOverlayScheme”)]
public static extern int PowerSetActiveOverlayScheme(Guid OverlaySchemeGuid);
[DllImport(“powrprof.dll”, EntryPoint=“PowerGetActualOverlayScheme”)]
public static extern int PowerGetActualOverlayScheme(out Guid ActualOverlayGuid);
[DllImport(“powrprof.dll”, EntryPoint=“PowerGetEffectiveOverlayScheme”)]
public static extern int PowerGetEffectiveOverlayScheme(out Guid EffectiveOverlayGuid);
$power = Add-Type -MemberDefinition $function -Name “Power” -PassThru -Namespace System.Runtime.InteropServices

$modes = @{
    "better_battery"     = [guid] "961cc777-2547-4f9d-8174-7d86181b8a7a";
    "better_performance" = [guid] "00000000000000000000000000000000";
    "best_performance"   = [guid] "ded574b5-45a0-4f42-8737-46345c09c238"

$actualOverlayGuid = [Guid]::NewGuid()
$ret = $power::PowerGetActualOverlayScheme([ref]$actualOverlayGuid)
if ($ret -eq 0) {
    "Actual power overlay scheme: $($($modes.GetEnumerator()|where {$_.value -eq  $actualOverlayGuid}).Key)." | Write-Host

$effectiveOverlayGuid = [Guid]::NewGuid()
$ret = $power::PowerGetEffectiveOverlayScheme([ref]$effectiveOverlayGuid)

if ($ret -eq 0) {        
    "Effective power overlay scheme: $($($modes.GetEnumerator() | where { $_.value -eq  $effectiveOverlayGuid }).Key)." | Write-Host
    $toggleOverlayGuid = if ($effectiveOverlayGuid -ne $modes["best_performance"]) { $modes["best_performance"] } else { $modes["better_performance"] }     
    # Toggle Power Mode
    $ret = $power::PowerSetActiveOverlayScheme($toggleOverlayGuid)
    if ($ret -eq 0) {
        "Toggled power overlay scheme to: $($($modes.GetEnumerator()| where { $_.value -eq  $toggleOverlayGuid }).Key)." | Write-Host

    $ret = $power::PowerSetActiveOverlayScheme($effectiveOverlayGuid)
    if ($ret -eq 0) {
        "Toggled power overlay scheme back to: $($($modes.GetEnumerator()|where {$_.value -eq  $effectiveOverlayGuid }).Key)." | Write-Host
else {
    "Failed to toggle active power overlay scheme." | Write-Host      


Execute the above

& $togglePowerOverlay

Welcome to the forum. :wave:t4:

Before we proceed … please go back, edit your question again and fix the formatting of your code …

When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in <---- Click :point_up_2:t4: :wink:

If you have an issue with or a question about the code you’ve found you should try to contact the author of the code first. He or she will be the one most familiar with the code.

Regardless of that you actually forgot to ask a question. :wink: What is it what’s not working as expected?