PR: Set-PowerPlan - Add Power and Sleep Button Actions

Task: Set-PowerPlan (official)

What:

  • Add Power Button Action
  • Add Sleep Button Action

Why: End users bump the power/sleep buttons, causing machine to go offline/unreachable in Immybot. Want Immybot to have ability to manage this setting similar to other power settings.

CC:

  • @DimitriRodis (original author?)
  • @DarrenDK : Any other user should @ mention for “PR”? Is there better way to subnit this?

Diff: PowerOptionsModule-Old.ps1<->PowerOptionsModule-New.ps1
--- "1/.\\PowerOptionsModule-Old.ps1"
+++ "2/.\\PowerOptionsModule-New.ps1"
@@ -440,6 +440,38 @@ function Set-PowerSchemeSettings {
                 SubGUID         = "4f971e89-eebd-4455-a8de-9e59040e7347"
                 SettingGUID     = "5ca83367-6e45-459f-a27b-476b1d01c936"
             }
+            PowerButtonActionAC        = @{
+                Description     = "Power Button action on AC"
+                RegistrySubPath = "\4f971e89-eebd-4455-a8de-9e59040e7347\7648efa3-dd9c-4e3e-b566-50f929386280"
+                SwitchCommand   = "/setacvalueindex"
+                NeedsSchemeGUID = $true
+                SubGUID         = "4f971e89-eebd-4455-a8de-9e59040e7347"
+                SettingGUID     = "7648efa3-dd9c-4e3e-b566-50f929386280"
+            }
+            PowerButtonActionDC        = @{
+                Description     = "Power Button action on DC"
+                RegistrySubPath = "\4f971e89-eebd-4455-a8de-9e59040e7347\7648efa3-dd9c-4e3e-b566-50f929386280"
+                SwitchCommand   = "/setdcvalueindex"
+                NeedsSchemeGUID = $true
+                SubGUID         = "4f971e89-eebd-4455-a8de-9e59040e7347"
+                SettingGUID     = "7648efa3-dd9c-4e3e-b566-50f929386280"
+            }
+            SleepButtonActionAC        = @{
+                Description     = "Sleep Button action on AC"
+                RegistrySubPath = "\4f971e89-eebd-4455-a8de-9e59040e7347\96996bc0-ad50-47ec-923b-6f41874dd9eb"
+                SwitchCommand   = "/setacvalueindex"
+                NeedsSchemeGUID = $true
+                SubGUID         = "4f971e89-eebd-4455-a8de-9e59040e7347"
+                SettingGUID     = "96996bc0-ad50-47ec-923b-6f41874dd9eb"
+            }
+            SleepButtonActionDC        = @{
+                Description     = "Sleep Button action on DC"
+                RegistrySubPath = "\4f971e89-eebd-4455-a8de-9e59040e7347\96996bc0-ad50-47ec-923b-6f41874dd9eb"
+                SwitchCommand   = "/setdcvalueindex"
+                NeedsSchemeGUID = $true
+                SubGUID         = "4f971e89-eebd-4455-a8de-9e59040e7347"
+                SettingGUID     = "96996bc0-ad50-47ec-923b-6f41874dd9eb"
+            }
             USBSelectiveSuspendAC   = @{
                 Description     = "USB Selective Suspend on AC"
                 RegistrySubPath = "\2a737441-1930-4402-8d77-b2bebba308a3\48e6b7a6-50f5-4782-a5d4-53bb8f07e226"
@@ -527,7 +559,7 @@ function Set-PowerSchemeSettings {
 
                 # Special case handling for the following settings
                 switch -Regex ($SettingName) {
-                    "LidCloseActionAC|LidCloseActionDC" {
+                    "LidCloseActionAC|LidCloseActionDC|PowerButtonActionAC|PowerButtonActionDC|SleepButtonActionAC|SleepButtonActionDC" {
                         $Index = switch ($Value) {
                             'Do Nothing' { 0 }
                             'Sleep' { 1 }
Diff: Set-PowerPlan (Official)-Old.ps1<->Set-PowerPlan (Official)-New.ps1
--- "1/.\\Set-PowerPlan (Official)-Old.ps1"	
+++ "2/.\\Set-PowerPlan (Official)-New.ps1"	
@@ -126,8 +126,11 @@ function Set-PowerScheme {
 	}
 }
 
-Function Get-LidCloseIndexFromValue
+Function Get-ActionIndexFromValue
 {
+	#Lid close Ref: https://learn.microsoft.com/en-us/windows-hardware/customize/power-settings/power-button-and-lid-settings-lid-switch-close-action
+	#Power Button Ref: https://learn.microsoft.com/en-us/windows-hardware/customize/power-settings/power-button-and-lid-settings-power-button-action
+	#Sleep Button Ref: https://learn.microsoft.com/en-us/windows-hardware/customize/power-settings/power-button-and-lid-settings-sleep-button-action
     param([string]$Value)
     switch($Value)
     {
@@ -205,6 +208,10 @@ function Set-PowerSchemeSettings {
 		[string]$HibernateTimeoutDC,
 		[string]$LidCloseActionAC,
 		[string]$LidCloseActionDC,
+		[string]$PowerButtonActionAC,
+		[string]$PowerButtonActionDC,
+		[string]$SleepButtonActionAC,
+		[string]$SleepButtonActionDC,
 		$USBSelectiveSuspendAC,
 		$USBSelectiveSuspendDC,
 		$PasswordProtectWakeupAC,
@@ -294,7 +301,7 @@ function Set-PowerSchemeSettings {
 		}
 	}
     if ($LidCloseActionAC) {
-		$Index = Get-LidCloseIndexFromValue $LidCloseActionAC
+		$Index = Get-ActionIndexFromValue $LidCloseActionAC
 		$Description = "Lid close action on AC....."
 		$RegArray += @{
 			Description = $Description
@@ -305,7 +312,7 @@ function Set-PowerSchemeSettings {
 		}
 	}
 	if ($LidCloseActionDC) {
-		$Index = Get-LidCloseIndexFromValue $LidCloseActionDC
+		$Index = Get-ActionIndexFromValue $LidCloseActionDC
 		$Description = "Lid close action on DC....."
 		$RegArray += @{
 			Description = $Description
@@ -316,6 +323,52 @@ function Set-PowerSchemeSettings {
 		}
 	}
 
+	if ($PowerButtonActionAC) {
+		$Index = Get-ActionIndexFromValue $PowerButtonActionAC
+		$Description = "Power Button action on AC....."
+		$RegArray += @{
+			Description = $Description
+			Switches = "/setacvalueindex $($Scheme.GUID) 4f971e89-eebd-4455-a8de-9e59040e7347 7648efa3-dd9c-4e3e-b566-50f929386280 $Index"
+			Path = "Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes\" + $Scheme.GUID + "\4f971e89-eebd-4455-a8de-9e59040e7347\7648efa3-dd9c-4e3e-b566-50f929386280"
+			Value = $Index
+			PowerIndex = "ACSettingIndex"
+		}
+	}
+	if ($PowerButtonActionDC) {
+		$Index = Get-ActionIndexFromValue $PowerButtonActionDC
+		$Description = "Power Button action on DC....."
+		$RegArray += @{
+			Description = $Description
+			Switches = "/setdcvalueindex $($Scheme.GUID) 4f971e89-eebd-4455-a8de-9e59040e7347 7648efa3-dd9c-4e3e-b566-50f929386280 $Index"
+			Path = "Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes\" + $Scheme.GUID + "\4f971e89-eebd-4455-a8de-9e59040e7347\7648efa3-dd9c-4e3e-b566-50f929386280"
+			Value = $Index
+			PowerIndex = "DCSettingIndex"
+		}
+	}
+
+	if ($SleepButtonActionAC) {
+		$Index = Get-ActionIndexFromValue $SleepButtonActionAC
+		$Description = "Sleep Button action on AC....."
+		$RegArray += @{
+			Description = $Description
+			Switches = "/setacvalueindex $($Scheme.GUID) 4f971e89-eebd-4455-a8de-9e59040e7347 96996bc0-ad50-47ec-923b-6f41874dd9eb $Index"
+			Path = "Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes\" + $Scheme.GUID + "\4f971e89-eebd-4455-a8de-9e59040e7347\96996bc0-ad50-47ec-923b-6f41874dd9eb"
+			Value = $Index
+			PowerIndex = "ACSettingIndex"
+		}
+	}
+	if ($SleepButtonActionDC) {
+		$Index = Get-ActionIndexFromValue $SleepButtonActionDC
+		$Description = "Sleep Button action on DC....."
+		$RegArray += @{
+			Description = $Description
+			Switches = "/setdcvalueindex $($Scheme.GUID) 4f971e89-eebd-4455-a8de-9e59040e7347 96996bc0-ad50-47ec-923b-6f41874dd9eb $Index"
+			Path = "Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes\" + $Scheme.GUID + "\4f971e89-eebd-4455-a8de-9e59040e7347\96996bc0-ad50-47ec-923b-6f41874dd9eb"
+			Value = $Index
+			PowerIndex = "DCSettingIndex"
+		}
+	}
+
     if ($null -ne $USBSelectiveSuspendAC) {
 		$Index = [int][bool]$USBSelectiveSuspendAC
 		$Description = "USB Selective Suspend on AC....."
@@ -381,7 +434,7 @@ function Set-PowerSchemeSettings {
 			$RegValue = Get-ItemProperty $Setting.Path -Name $Setting.PowerIndex -ErrorAction SilentlyContinue | %{$_."$($Setting.PowerIndex)"}
 			Write-Host "RegValue: $RegValue"
 			# if(!(!([string]::IsNullOrEmpty($USBSelectiveSuspendDC) -or ![string]::IsNullOrEmpty($LidCloseActionAC))))
-			if($Setting.Description -notmatch "PasswordProtectWakeup|Lid close action|USB Selective Suspend")
+			if($Setting.Description -notmatch "PasswordProtectWakeup|Lid close action|Power Button action|Sleep Button action|USB Selective Suspend")
 			{
 				$RegValue /= 60
 			}
@@ -431,6 +484,10 @@ $TestResult = (Set-PowerSchemeSettings -Validate -HibernateTimeoutAC $HibernateT
 $TestResult = (Set-PowerSchemeSettings -Validate -HibernateTimeoutDC $HibernateTimeoutDC) -and $TestResult
 $TestResult = (Set-PowerSchemeSettings -Validate -LidCloseActionAC $LidCloseActionAC) -and $TestResult
 $TestResult = (Set-PowerSchemeSettings -Validate -LidCloseActionDC $LidCloseActionDC) -and $TestResult
+$TestResult = (Set-PowerSchemeSettings -Validate -PowerButtonActionAC $PowerButtonActionAC) -and $TestResult
+$TestResult = (Set-PowerSchemeSettings -Validate -PowerButtonActionDC $PowerButtonActionDC) -and $TestResult
+$TestResult = (Set-PowerSchemeSettings -Validate -SleepButtonActionAC $SleepButtonActionAC) -and $TestResult
+$TestResult = (Set-PowerSchemeSettings -Validate -SleepButtonActionDC $SleepButtonActionDC) -and $TestResult
 $TestResult = (Set-PowerSchemeSettings -Validate -USBSelectiveSuspendAC $USBSelectiveSuspendAC) -and $TestResult
 $TestResult = (Set-PowerSchemeSettings -Validate -USBSelectiveSuspendDC $USBSelectiveSuspendDC) -and $TestResult
 $TestResult = (Set-PowerSchemeSettings -Validate -PasswordProtectWakeupAC $PasswordProtectWakeupAC) -and $TestResult
@@ -483,6 +540,10 @@ $TestResult = (Set-PowerSchemeSettings -Validate -PasswordProtectWakeupDC $Passw
         Set-PowerSchemeSettings -Config -HibernateTimeoutDC $HibernateTimeoutDC
         Set-PowerSchemeSettings -Config -LidCloseActionAC $LidCloseActionAC
         Set-PowerSchemeSettings -Config -LidCloseActionDC $LidCloseActionDC
+				Set-PowerSchemeSettings -Config -PowerButtonActionAC $PowerButtonActionAC
+        Set-PowerSchemeSettings -Config -PowerButtonActionDC $PowerButtonActionDC
+				Set-PowerSchemeSettings -Config -SleepButtonActionAC $SleepButtonActionAC
+        Set-PowerSchemeSettings -Config -SleepButtonActionDC $SleepButtonActionDC
         Set-PowerSchemeSettings -Config -USBSelectiveSuspendAC $USBSelectiveSuspendAC
         Set-PowerSchemeSettings -Config -USBSelectiveSuspendDC $USBSelectiveSuspendDC
         Set-PowerSchemeSettings -Config -PasswordProtectWakeupAC $PasswordProtectWakeupAC


Updated files in next post(s) [due to character limit of posts and can’t attach .ps1 or .txt]

PowerOptionsModule.ps1 Updated
function Get-PowerConfiguration {
    param(
        [Parameter(Mandatory)]
        [string]$Name,

        [Parameter(Mandatory)]
        [string]$SchemeGUID,

        [string]$SubGUID,

        [string]$SettingGUID,

        [Parameter(Mandatory)]
        [ValidateSet("ACSettingIndex", "DCSettingIndex")]
        [string]$PowerIndex
    )

    $OriginalVerbosePreference = $VerbosePreference

    try {
        $VerbosePreference = 'SilentlyContinue'

        # For "LidCloseAction" and "SystemUnattendedSleep", temporarily unhide the setting to ensure it can be queried with `powercfg /query`.
        # This step is necessary because some settings might be hidden by default, making them inaccessible for querying.
        # The setting is unhidden, queried, and then hidden again to maintain original system configuration visibility.
        $UnhideSettings = @{
            "LidCloseAction"        = @{ Guid = "5ca83367-6e45-459f-a27b-476b1d01c936"; SubCategory = "SUB_BUTTONS" }
            "SystemUnattendedSleep" = @{ Guid = "7bc4a2f9-d8fc-4469-b07b-33eb785aaca0"; SubCategory = "SUB_SLEEP" }
        }

        $BaseName = $Name -replace "(AC|DC)$", ""
        if ($UnhideSettings.ContainsKey($BaseName)) {
            $Guid = $UnhideSettings[$BaseName].Guid
            $SubCategory = $UnhideSettings[$BaseName].SubCategory
            Set-PowerConfiguration "-attributes $SubCategory $Guid -ATTRIB_HIDE" -Verbose:$false | Out-Null
            $QueryResult = Set-PowerConfiguration "/query $SchemeGUID $SubGUID $SettingGUID"
            Set-PowerConfiguration "-attributes $SubCategory $Guid +ATTRIB_HIDE" -Verbose:$false | Out-Null
        } else {
            $QueryResult = Set-PowerConfiguration "/query $SchemeGUID $SubGUID $SettingGUID"
        }

        $Result = Invoke-ImmyCommand {
            $Name = $using:Name
            $SchemeGUID = $using:SchemeGUID
            $SubGUID = $using:SubGUID
            $SettingGUID = $using:SettingGUID
            $PowerIndex = $using:PowerIndex
            $QueryResult = $using:QueryResult
            $OriginalVerbosePreference = $using:OriginalVerbosePreference
            $VerbosePreference = $using:VerbosePreference

            try {
                # Determine the correct label for the PowerIndex to construct the regex pattern
                $Label = if ($PowerIndex -eq "ACSettingIndex") { "AC" } else { "DC" }
                $Pattern = "Current $Label Power Setting Index:\s+0x([0-9A-F]+)"
                $SettingsWithoutSecondsConversion = "PasswordProtectWakeup|LidCloseAction|USBSelectiveSuspend|SystemUnattendedSleep"

                $Value = $null
                $Match = $QueryResult | Select-String -Pattern $Pattern

                if ($Match) {
                    $HexValue = $Match.Matches.Groups[1].Value
                    if ($Name -notmatch $SettingsWithoutSecondsConversion) {
                        $Value = [convert]::ToInt32($HexValue, 16) / 60
                    } else {
                        $Value = [convert]::ToInt32($HexValue, 16)
                    }
                } else {
                    Write-Warning "Failed to parse the value!"
                }

                return $Value
            } finally {
                $VerbosePreference = $OriginalVerbosePreference
            }
        }

        return $Result
    } finally {
        $VerbosePreference = $OriginalVerbosePreference
    }
}

function Set-PowerConfiguration {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory, Position = 0)]
        [string]$PFGArguments,
        [string]$CommandTitle
    )

    $result = Invoke-ImmyCommand {
        $CommandPath = "C:\Windows\System32\powercfg.exe"
        $CommandArguments = $using:PFGArguments
        $CommandTitle = $using:CommandTitle

        Write-Verbose "Running: $CommandPath $CommandArguments"

        $pinfo = New-Object System.Diagnostics.ProcessStartInfo
        $pinfo.FileName = $CommandPath
        $pinfo.RedirectStandardError = $true
        $pinfo.RedirectStandardOutput = $true
        $pinfo.UseShellExecute = $false
        $pinfo.Arguments = $CommandArguments
        $p = New-Object System.Diagnostics.Process
        $p.StartInfo = $pinfo
        $p.Start() | Out-Null
        $p.WaitForExit()

        # Now that the process has exited, it's safe to read the output, error, and exit code
        New-Object PSObject -Property @{
            commandTitle = $CommandTitle
            stdout       = $p.StandardOutput.ReadToEnd()
            stderr       = $p.StandardError.ReadToEnd()
            ExitCode     = $p.ExitCode
        }
    }

    $result | ForEach-Object { $_.stdout }
}

function Get-PowerScheme {
    <#
    .SYNOPSIS
        Get the currently active PowerScheme
    .DESCRIPTION
        This will query the current power scheme and return the GUID and user friendly name
    .EXAMPLE
        PS C:\> Get-PowerScheme
    .NOTES
        Additional information about the function.
    #>
    [OutputType([object])]
    [CmdletBinding()]
    param()

    $Query = Set-PowerConfiguration "/getactivescheme" # Example Output: Power Scheme GUID: 9f48bc40-60d6-419a-b775-90138987007b  (NoSleepOrStandby)
    try {
        if ($Query -match "Power Scheme GUID: ([\w-]+)  \((.+)\)") {
            $ActiveSchemeGUID = $matches[1]
            $ActiveSchemeName = $matches[2]
        } else {
            Write-Warning "Failed to extract GUID or name from the output"
            return $null
        }

        $Scheme = New-Object PSObject -Property @{
            PowerScheme = $ActiveSchemeName
            GUID        = $ActiveSchemeGUID
        }

        return $Scheme
    } catch {
        Write-Warning "'Get-PowerScheme' failure. Error may be:`n$Query"
        return $null
    }
}

function Set-PowerScheme {
    <#
    .SYNOPSIS
        Sets the power scheme to the specified scheme
    .DESCRIPTION
        This function sets the power scheme to the specified scheme
    .PARAMETER PowerScheme
        The name of the power scheme to set
    .PARAMETER PassThru
        If specified, the function will return the GUID of the power scheme that was set
    .EXAMPLE
        PS C:\> Set-PowerScheme -PowerScheme 'Value1'
    #>
    param(
        [string]$PowerScheme,
        [switch]$PassThru
    )

    Write-Verbose "Getting active power scheme before setting"
    $ActivePowerScheme = Get-PowerScheme
    if ($null -eq $ActivePowerScheme) {
        Write-Warning "Unable to retrieve the active power scheme."
        return $null
    }

    Write-Host ""
    Write-Verbose "ActivePowerScheme $($ActivePowerScheme | Format-List PowerScheme, GUID | Out-String)"
    Write-Host ""

    # Get a list of existing power schemes
    Write-Verbose "Getting list of power schemes to match against"
    $PowerSchemesOutput = Set-PowerConfiguration "/l"
    if ($null -ne $PowerScheme -and $PowerScheme -ne "") {
        Write-Verbose $PowerSchemesOutput
        Write-Host ""

        #$PowerSchemePattern = '(?<Guid>(?:[0-9a-fA-F]){8}-(?:[0-9a-fA-F]){4}-(?:[0-9a-fA-F]){4}-(?:[0-9a-fA-F]){4}-(?:[0-9a-fA-F]){12})\s*\((?<SchemeName>[A-Za-z\d\s_]+)\)\s*(?<Active>\*)?'
        $PowerSchemePattern = '(?<Guid>[0-9a-fA-F]{8}-(?:[0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12})\s*\((?<SchemeName>.+)\)\s*(?<Active>\*)?'
        $AllPowerSchemes = Select-String -InputObject $PowerSchemesOutput -Pattern $PowerSchemePattern -AllMatches
        $GuidPowerSchemeToSet = $AllPowerSchemes.Matches | Where-Object {
            $_.Groups['SchemeName'].Value -eq $PowerScheme
        } | ForEach-Object { $_.Groups['Guid'].Value } | Select-Object -First 1

        if ($GuidPowerSchemeToSet -and $GuidPowerSchemeToSet -ne $ActivePowerScheme.GUID) {
            Write-Verbose "Setting Power Scheme from '$($ActivePowerScheme.PowerScheme)' to '$($PowerScheme)'"
            Set-PowerConfiguration "/setactive $GuidPowerSchemeToSet"
            Write-Verbose "Getting active power scheme after setting"
            $ActivePowerScheme = Get-PowerScheme

            if ($PowerScheme -eq $ActivePowerScheme.PowerScheme) {
                Write-Verbose "Successfully set power scheme"
            } else {
                Write-Warning "Failed to set power scheme!"
                return $null
            }
        } else {
            Write-Verbose "Power scheme is already set to the desired scheme"
        }

        if ($PassThru) {
            if ($null -ne $GuidPowerSchemeToSet) {
                return $GuidPowerSchemeToSet
            } else {
                Write-Warning "GuidPowerSchemeToSet is null"
                return $null
            }
        }
    }

    return $null
}

function Set-PowerSchemeSettings {
    <#
    .SYNOPSIS
        Applies or validates power scheme settings based on provided configurations.
    .DESCRIPTION
        This function configures or validates settings for a specified power scheme.
        It allows for dynamic application or validation of multiple settings within a power scheme.
        The function supports both applying new settings and validating existing settings against expected values.
    .PARAMETER Scheme
        The power scheme object to which settings will be applied or validated.
        This should be an object containing at least the GUID of the power scheme.
    .PARAMETER Settings
        A hashtable of settings to be applied or validated.
        Keys should be the setting names (e.g., 'MonitorTimeoutAC'), and values should be the desired setting values.
    .PARAMETER Validate
        If specified, the function will validate the current settings of the power scheme
        against the provided settings without applying any changes.
    .PARAMETER Config
        If specified, the function will apply the provided settings to the power scheme.
        This parameter is mutually exclusive with -Validate.
    .EXAMPLE
        $scheme = Get-PowerScheme -Name 'Balanced'
        $settings = @{
            MonitorTimeoutAC = 10
            DiskTimeoutDC = 5
        }
        Set-PowerSchemeSettings -Scheme $scheme -Settings $settings -Config

        Applies a monitor timeout of 10 minutes when on AC power and a disk timeout of 5 minutes when on DC power to the 'Balanced' power scheme.
    .EXAMPLE
        $scheme = Get-PowerScheme -Name 'High Performance'
        $settings = @{
            USBSelectiveSuspendAC = $true
            HibernateTimeoutDC = 20
        }
        Set-PowerSchemeSettings -Scheme $scheme -Settings $settings -Validate

        Validates if the 'High Performance' power scheme has USB selective suspend enabled on AC power and a hibernate timeout of 20 minutes on DC power.
    .NOTES
        Ensure that the provided $Scheme object contains the necessary information to identify the power scheme, typically a GUID.
        The $Settings hashtable keys must match the expected configuration setting names recognized by the system.
    #>
    [CmdletBinding(DefaultParameterSetName = 'None')]
    param(
        [Parameter(Mandatory)]
        [psobject]$Scheme,

        [Parameter(Mandatory)]
        [System.Collections.Specialized.OrderedDictionary]$Settings,

        [Parameter(Mandatory = $false)]
        [bool]$EnforceWithPolicy = $true,

        [Parameter(ParameterSetName = 'ValidateSet')]
        [switch]$Validate,

        [Parameter(ParameterSetName = 'ConfigSet')]
        [switch]$Config
    )

    if ($PSCmdlet.ParameterSetName -eq 'None') {
        throw "You must specify either -Validate or -Config"
    }

    $PowerSettingsRegPath = "Registry::HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Power\PowerSettings"
    $ActiveGUID = $Scheme.GUID

    $result = Invoke-ImmyCommand {
        $ActiveGUID = $using:ActiveGUID
        $PowerSettingsRegPath = $using:PowerSettingsRegPath
        $Settings = $using:Settings
        $EnforceWithPolicy = $using:EnforceWithPolicy
        $Validate = $using:Validate
        $Config = $using:Config

        $ActiveSchemeValue = (Get-ItemProperty -Path $PowerSettingsRegPath -Name "ActivePowerScheme" -ErrorAction Ignore).ActivePowerScheme
        $ActiveSchemeValueCorrect = $null -ne $ActiveSchemeValue -and $ActiveSchemeValue -eq $ActiveGUID
        $PreferredPlanGUID = "{025A5937-A6BE-4686-A844-36FE4BEC8B6D}"
        $PreferredPlanPath = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel\NameSpace\$PreferredPlanGUID"
        $CurrentPreferredScheme = Get-ItemProperty -Path $PreferredPlanPath -Name PreferredPlan -ErrorAction Ignore
        $CurrentPreferredSchemeCorrect = $CurrentPreferredScheme.PreferredPlan -eq $ActiveGUID

        $ValidateResult = $true
        if ($Validate) {
            if ($EnforceWithPolicy) {
                if (-not $ActiveSchemeValue -or -not $ActiveSchemeValueCorrect) {
                    Write-Warning "Validation failed for 'ActivePowerScheme'. Key does not exist or does not match the expected GUID: $ActiveGUID"
                    Write-Verbose $PowerSettingsRegPath
                    $ValidateResult = $false
                }
            } elseif ($EnforceWithPolicy -eq $false) {
                if ($ActiveSchemeValue) {
                    $ValidateResult = $false
                }
            }

            if ($CurrentPreferredSchemeCorrect -eq $false) {
                Write-Verbose "The 'PreferredPlan' registry key does not match the expected GUID: $ActiveGUID"
                Write-Verbose $PreferredPlanPath
                $ValidateResult = $false
            }
        }

        $PendingPolicyEnforcement = $false
        if ($Config) {
            if ($EnforceWithPolicy) {
                $PendingPolicyEnforcement = $true
            } elseif ($EnforceWithPolicy -eq $false) {
                $PropertyExists = $null -ne $ActiveSchemeValue
                if ($PropertyExists) {
                    Write-Verbose "Removing 'ActivePowerScheme' from the registry as policy enforcement is disabled."
                    Remove-ItemProperty -Path $PowerSettingsRegPath -Name "ActivePowerScheme" -Force
                }
            }

            if ($CurrentPreferredSchemeCorrect -eq $false) {
                # Setting the PreferredPlan value is necessary to reflect the correct settings within the Control Panel
                Write-Verbose "Setting 'PreferredPlan' to '$ActiveGUID' in the registry."
                Set-ItemProperty -Path $PreferredPlanPath -Name PreferredPlan -Value $ActiveGUID -Force | Out-Null
            }
        }

        # Define a mapping of setting names to registry paths and switch commands
        $SettingMap = @{
            MonitorTimeoutAC        = @{
                Description     = "Monitor timeout on AC in minutes"
                RegistrySubPath = "\7516b95f-f776-4464-8c53-06167f40cc99\3c0bc021-c8a8-4e07-a973-6b14cbcb2b7e"
                SwitchCommand   = "/change monitor-timeout-ac"
                SubGUID         = "7516b95f-f776-4464-8c53-06167f40cc99"
                SettingGUID     = "3c0bc021-c8a8-4e07-a973-6b14cbcb2b7e"
            }
            MonitorTimeoutDC        = @{
                Description     = "Monitor timeout on DC in minutes"
                RegistrySubPath = "\7516b95f-f776-4464-8c53-06167f40cc99\3c0bc021-c8a8-4e07-a973-6b14cbcb2b7e"
                SwitchCommand   = "/change monitor-timeout-dc"
                SubGUID         = "7516b95f-f776-4464-8c53-06167f40cc99"
                SettingGUID     = "3c0bc021-c8a8-4e07-a973-6b14cbcb2b7e"
            }
            DiskTimeoutAC           = @{
                Description     = "Disk timeout on AC in minutes"
                RegistrySubPath = "\0012ee47-9041-4b5d-9b77-535fba8b1442\6738e2c4-e8a5-4a42-b16a-e040e769756e"
                SwitchCommand   = "/change disk-timeout-ac"
                SubGUID         = "0012ee47-9041-4b5d-9b77-535fba8b1442"
                SettingGUID     = "6738e2c4-e8a5-4a42-b16a-e040e769756e"
            }
            DiskTimeoutDC           = @{
                Description     = "Disk timeout on DC in minutes"
                RegistrySubPath = "\0012ee47-9041-4b5d-9b77-535fba8b1442\6738e2c4-e8a5-4a42-b16a-e040e769756e"
                SwitchCommand   = "/change disk-timeout-dc"
                SubGUID         = "0012ee47-9041-4b5d-9b77-535fba8b1442"
                SettingGUID     = "6738e2c4-e8a5-4a42-b16a-e040e769756e"
            }
            StandbyTimeoutAC        = @{
                Description     = "Standby timeout on AC in minutes"
                RegistrySubPath = "\238c9fa8-0aad-41ed-83f4-97be242c8f20\29f6c1db-86da-48c5-9fdb-f2b67b1f44da"
                SwitchCommand   = "/change standby-timeout-ac"
                SubGUID         = "238c9fa8-0aad-41ed-83f4-97be242c8f20"
                SettingGUID     = "29f6c1db-86da-48c5-9fdb-f2b67b1f44da"
            }
            StandbyTimeoutDC        = @{
                Description     = "Standby timeout on DC in minutes"
                RegistrySubPath = "\238c9fa8-0aad-41ed-83f4-97be242c8f20\29f6c1db-86da-48c5-9fdb-f2b67b1f44da"
                SwitchCommand   = "/change standby-timeout-dc"
                SubGUID         = "238c9fa8-0aad-41ed-83f4-97be242c8f20"
                SettingGUID     = "29f6c1db-86da-48c5-9fdb-f2b67b1f44da"
            }
            SystemUnattendedSleepAC = @{
                Description      = "System unattended sleep timeout on AC in minutes"
                RegistrySubPath  = "\238C9FA8-0AAD-41ED-83F4-97BE242C8F20\7bc4a2f9-d8fc-4469-b07b-33eb785aaca0"
                SwitchCommand    = "/setacvalueindex"
                NeedsSchemeGUID  = $true
                SubGUID          = "238c9fa8-0aad-41ed-83f4-97be242c8f20"
                SettingGUID      = "7bc4a2f9-d8fc-4469-b07b-33eb785aaca0"
            }
            SystemUnattendedSleepDC = @{
                Description      = "System unattended sleep timeout on DC in minutes"
                RegistrySubPath  = "\238C9FA8-0AAD-41ED-83F4-97BE242C8F20\7bc4a2f9-d8fc-4469-b07b-33eb785aaca0"
                SwitchCommand    = "/setdcvalueindex"
                NeedsSchemeGUID  = $true
                SubGUID          = "238c9fa8-0aad-41ed-83f4-97be242c8f20"
                SettingGUID      = "7bc4a2f9-d8fc-4469-b07b-33eb785aaca0"
            }
            HibernateTimeoutAC      = @{
                Description     = "Hibernate timeout on AC in minutes"
                RegistrySubPath = "\238c9fa8-0aad-41ed-83f4-97be242c8f20\9d7815a6-7ee4-497e-8888-515a05f02364"
                SwitchCommand   = "/change hibernate-timeout-ac"
                SubGUID         = "238c9fa8-0aad-41ed-83f4-97be242c8f20"
                SettingGUID     = "9d7815a6-7ee4-497e-8888-515a05f02364"
            }
            HibernateTimeoutDC      = @{
                Description     = "Hibernate timeout on DC in minutes"
                RegistrySubPath = "\238c9fa8-0aad-41ed-83f4-97be242c8f20\9d7815a6-7ee4-497e-8888-515a05f02364"
                SwitchCommand   = "/change hibernate-timeout-dc"
                SubGUID         = "238c9fa8-0aad-41ed-83f4-97be242c8f20"
                SettingGUID     = "9d7815a6-7ee4-497e-8888-515a05f02364"
            }
            LidCloseActionAC        = @{
                Description     = "Lid close action on AC"
                RegistrySubPath = "\4f971e89-eebd-4455-a8de-9e59040e7347\5ca83367-6e45-459f-a27b-476b1d01c936"
                SwitchCommand   = "/setacvalueindex"
                NeedsSchemeGUID = $true
                SubGUID         = "4f971e89-eebd-4455-a8de-9e59040e7347"
                SettingGUID     = "5ca83367-6e45-459f-a27b-476b1d01c936"
            }
            LidCloseActionDC        = @{
                Description     = "Lid close action on DC"
                RegistrySubPath = "\4f971e89-eebd-4455-a8de-9e59040e7347\5ca83367-6e45-459f-a27b-476b1d01c936"
                SwitchCommand   = "/setdcvalueindex"
                NeedsSchemeGUID = $true
                SubGUID         = "4f971e89-eebd-4455-a8de-9e59040e7347"
                SettingGUID     = "5ca83367-6e45-459f-a27b-476b1d01c936"
            }
            PowerButtonActionAC        = @{
                Description     = "Power Button action on AC"
                RegistrySubPath = "\4f971e89-eebd-4455-a8de-9e59040e7347\7648efa3-dd9c-4e3e-b566-50f929386280"
                SwitchCommand   = "/setacvalueindex"
                NeedsSchemeGUID = $true
                SubGUID         = "4f971e89-eebd-4455-a8de-9e59040e7347"
                SettingGUID     = "7648efa3-dd9c-4e3e-b566-50f929386280"
            }
            PowerButtonActionDC        = @{
                Description     = "Power Button action on DC"
                RegistrySubPath = "\4f971e89-eebd-4455-a8de-9e59040e7347\7648efa3-dd9c-4e3e-b566-50f929386280"
                SwitchCommand   = "/setdcvalueindex"
                NeedsSchemeGUID = $true
                SubGUID         = "4f971e89-eebd-4455-a8de-9e59040e7347"
                SettingGUID     = "7648efa3-dd9c-4e3e-b566-50f929386280"
            }
            SleepButtonActionAC        = @{
                Description     = "Sleep Button action on AC"
                RegistrySubPath = "\4f971e89-eebd-4455-a8de-9e59040e7347\96996bc0-ad50-47ec-923b-6f41874dd9eb"
                SwitchCommand   = "/setacvalueindex"
                NeedsSchemeGUID = $true
                SubGUID         = "4f971e89-eebd-4455-a8de-9e59040e7347"
                SettingGUID     = "96996bc0-ad50-47ec-923b-6f41874dd9eb"
            }
            SleepButtonActionDC        = @{
                Description     = "Sleep Button action on DC"
                RegistrySubPath = "\4f971e89-eebd-4455-a8de-9e59040e7347\96996bc0-ad50-47ec-923b-6f41874dd9eb"
                SwitchCommand   = "/setdcvalueindex"
                NeedsSchemeGUID = $true
                SubGUID         = "4f971e89-eebd-4455-a8de-9e59040e7347"
                SettingGUID     = "96996bc0-ad50-47ec-923b-6f41874dd9eb"
            }
            USBSelectiveSuspendAC   = @{
                Description     = "USB Selective Suspend on AC"
                RegistrySubPath = "\2a737441-1930-4402-8d77-b2bebba308a3\48e6b7a6-50f5-4782-a5d4-53bb8f07e226"
                SwitchCommand   = "/setacvalueindex"
                NeedsSchemeGUID = $true
                SubGUID         = "2a737441-1930-4402-8d77-b2bebba308a3"
                SettingGUID     = "48e6b7a6-50f5-4782-a5d4-53bb8f07e226"
            }
            USBSelectiveSuspendDC   = @{
                Description     = "USB Selective Suspend on DC"
                RegistrySubPath = "\2a737441-1930-4402-8d77-b2bebba308a3\48e6b7a6-50f5-4782-a5d4-53bb8f07e226"
                SwitchCommand   = "/setdcvalueindex"
                NeedsSchemeGUID = $true
                SubGUID         = "2a737441-1930-4402-8d77-b2bebba308a3"
                SettingGUID     = "48e6b7a6-50f5-4782-a5d4-53bb8f07e226"
            }
            PasswordProtectWakeupAC = @{
                Description      = "PasswordProtectWakeup on AC"
                RegistrySubPath  = "\0E796BDB-100D-47D6-A2D5-F7D2DAA51F51"
                SwitchCommand    = "/setacvalueindex"
                NeedsSchemeGUID  = $true
                AdditionalParams = "SUB_NONE CONSOLELOCK"
                SubGUID          = "0E796BDB-100D-47D6-A2D5-F7D2DAA51F51"
            }
            PasswordProtectWakeupDC = @{
                Description      = "PasswordProtectWakeup on DC"
                RegistrySubPath  = "\0E796BDB-100D-47D6-A2D5-F7D2DAA51F51"
                SwitchCommand    = "/setdcvalueindex"
                NeedsSchemeGUID  = $true
                AdditionalParams = "SUB_NONE CONSOLELOCK"
                SubGUID          = "0E796BDB-100D-47D6-A2D5-F7D2DAA51F51"
            }
        }

        $CommandsToExecute = [System.Collections.Generic.List[hashtable]]::new()
        foreach ($SettingName in $Settings.Keys) {
            $SettingDetails = $SettingMap[$SettingName]
            if ($null -eq $SettingDetails) {
                Write-Warning "Setting '$SettingName' is not recognized"
                continue
            }

            # Initial assignment of $Value
            $Value = $Settings[$SettingName]
            if ($null -eq $Value) {
                Write-Debug "Skipping setting '$SettingName' because its value is null"
                continue
            }

            # Initialize command parameters with the switch command
            $SwitchCommand = $SettingDetails.SwitchCommand

            # Determine if the setting is one of the universal settings that do not require a scheme GUID
            $UniversalSettings = @(
                "MonitorTimeoutAC",
                "MonitorTimeoutDC",
                "DiskTimeoutAC",
                "DiskTimeoutDC",
                "StandbyTimeoutAC",
                "StandbyTimeoutDC",
                "HibernateTimeoutAC",
                "HibernateTimeoutDC"
            )
            if ($UniversalSettings -contains $SettingName) {
                # For universal settings, directly append the value
                $Switches = "$SwitchCommand $Value"
            } else {
                $CommandParameters = ""
                # Conditionally append Scheme GUID and additional GUIDs
                if ($SettingDetails.NeedsSchemeGUID) {
                    $CommandParameters += " $ActiveGUID"
                }
                # Check and append Subgroup GUID (SubGUID) and Setting GUID if they are present
                if ($SettingDetails.SubGUID) {
                    $CommandParameters += " $($SettingDetails.SubGUID)"
                }
                if ($SettingDetails.SettingGUID) {
                    $CommandParameters += " $($SettingDetails.SettingGUID)"
                }

                # Append AdditionalParams if specified (for PasswordProtectWakeup settings)
                if ($SettingDetails.AdditionalParams) {
                    $CommandParameters += " $($SettingDetails.AdditionalParams)"
                }

                # Special case handling for the following settings
                switch -Regex ($SettingName) {
                    "LidCloseActionAC|LidCloseActionDC|PowerButtonActionAC|PowerButtonActionDC|SleepButtonActionAC|SleepButtonActionDC" {
                        $Index = switch ($Value) {
                            'Do Nothing' { 0 }
                            'Sleep' { 1 }
                            'Hibernate' { 2 }
                            'Shut Down' { 3 }
                        }
                        $Value = $Index # Adjust value for these settings
                    }
                    "USBSelectiveSuspendAC|USBSelectiveSuspendDC|PasswordProtectWakeupAC|PasswordProtectWakeupDC" {
                        $Value = [int][bool]$Value # Convert boolean to integer for these settings
                    }
                }

                # Finalize command parameters with the value and construct the complete switch command
                $CommandParameters += " $Value"
                $Switches = "$SwitchCommand$CommandParameters"
            }

            # Assign the setting details
            $Description = $SettingDetails.Description
            $RegistrySubPath = $SettingDetails.RegistrySubPath
            $PowerIndex = if ($SettingName -match "AC$") { "ACSettingIndex" } elseif ($SettingName -match "DC$") { "DCSettingIndex" }
            $Path = $PowerSettingsRegPath + $RegistrySubPath

            if ($Config) {
                $Params = @{
                    Description = $Description
                    SettingName = $SettingName
                    Switches    = $Switches
                    Path        = $Path
                }
                $CommandsToExecute.Add(
                    @{ Command = 'Config'; Parameters = $Params; ExpectedValue = $Value }
                )
            }

            if ($Validate) {
                $Params = @{
                    Name        = $SettingName
                    SchemeGUID  = $ActiveGUID
                    SubGUID     = $SettingDetails.SubGUID
                    SettingGUID = $SettingDetails.SettingGUID
                    PowerIndex  = $PowerIndex
                }
                $CommandsToExecute.Add(
                    @{ Command = 'Validate'; Parameters = $Params; Description = $Description; Path = $Path; ExpectedValue = $Value }
                )
            }
        }

        return [pscustomobject]@{
            Commands                 = $CommandsToExecute
            PendingPolicyEnforcement = $PendingPolicyEnforcement
            ValidateResult           = $ValidateResult
        }
    }

    $PendingPolicyEnforcement = $result.PendingPolicyEnforcement
    $ValidateResult = $result.ValidateResult

    foreach ($command in $result.Commands) {
        if ($command.Command -eq 'Config') {
            $Params = $command.Parameters
            $Value = $command.ExpectedValue
            $SettingName = $Params.SettingName
            $Description = $Params.Description
            $Switches = $Params.Switches
            $Path = $Params.Path
            Write-Host "Applying: '$Description' with value: $Value"
            if ($SettingName -match "PasswordProtectWakeup") {
                Invoke-ImmyCommand {
                    $Path = $using:Path
                    $SettingName = $using:SettingName
                    $Value = $using:Value
                    if (-not (Test-Path $Path)) {
                        New-Item -Path $Path -ItemType Directory -Force | Out-Null
                    }
                    Set-ItemProperty -Path $Path -Name $SettingName -Value $Value -Force | Out-Null
                }
            } else {
                Set-PowerConfiguration -PFGArguments $Switches
            }
        } elseif ($command.Command -eq 'Validate') {
            $Params = $command.Parameters
            $SettingName = $Params.Name
            $Description = $command.Description
            $Value = $command.ExpectedValue
            $Path = $command.Path
            Write-Host "Validating: '$Description' " -NoNewline
            if ($SettingName -match "PasswordProtectWakeup") {
                $CurrentValue = Invoke-ImmyCommand {
                    $SettingName = $using:SettingName
                    (Get-ItemProperty -Path $using:Path -Name $using:SettingName -ErrorAction Ignore).$SettingName
                }
            } else {
                $CurrentValue = Get-PowerConfiguration @Params
            }

            if ($Value -ne $CurrentValue) {
                Write-Warning "Validation failed for '$SettingName'. Expected: $Value, Found: $CurrentValue"
                $ValidateResult = $false
            } else {
                Write-Host "Expected: $Value, Found: $CurrentValue"
            }
        }
    }

    if ($PendingPolicyEnforcement) {
        # Enforcing the power policy by setting the active power scheme through the registry.
        # This ensures compliance with Windows policy, reverting unauthorized changes upon policy refresh.
        Invoke-ImmyCommand {
            $PowerSettingsRegPath = $using:PowerSettingsRegPath
            $ActiveGUID = $using:ActiveGUID
            if (-not (Test-Path $PowerSettingsRegPath)) {
                New-Item -Path $PowerSettingsRegPath -ItemType Directory -Force | Out-Null
            }
            Write-Verbose "Enforcing the policy by setting 'ActivePowerScheme' to '$ActiveGUID' in the registry."
            Set-ItemProperty -Path $PowerSettingsRegPath -Name "ActivePowerScheme" -Value $ActiveGUID -Force | Out-Null
        }
    }

    # In case no values were tested
    return $ValidateResult
}

Export-ModuleMember -Function @(
    "Get-PowerConfiguration",
    "Set-PowerConfiguration",
    "Get-PowerScheme",
    "Set-PowerScheme",
    "Set-PowerSchemeSettings"
)
Set-PowerPlan (Official).ps1 Updated
# if($method -eq "test")
# {
#     Function Write-Host { }
# }

Function Execute-Command
{
	param([string]$commandTitle, [string]$commandPath, [string]$commandArguments)
    $pinfo = New-Object System.Diagnostics.ProcessStartInfo
    $pinfo.FileName = $commandPath
    $pinfo.RedirectStandardError = $true
    $pinfo.RedirectStandardOutput = $true
    $pinfo.UseShellExecute = $false
    $pinfo.Arguments = $commandArguments
    $p = New-Object System.Diagnostics.Process
    $p.StartInfo = $pinfo
    $p.Start() | Out-Null
    [pscustomobject]@{
        commandTitle = $commandTitle
        stdout = $p.StandardOutput.ReadToEnd()
        stderr = $p.StandardError.ReadToEnd()
        ExitCode = $p.ExitCode
    }
    $p.WaitForExit()
}

Function Configure-Power
{
	param($PFGArguments)
	$powercfgexe = "C:\Windows\System32\powercfg.exe"
	Write-Host "Running $powercfgexe $PFGArguments"
	Execute-Command -commandPath $powercfgexe -commandArguments $PFGArguments | %{$_.StdOut}
	#Start-Process -FilePath $powercfgexe -ArgumentList $PFGArguments | %{$_.StdOut}
}
function Get-PowerScheme {
<#
	.SYNOPSIS
		Get the currently active PowerScheme

	.DESCRIPTION
		This will query the current power scheme and return the GUID and user friendly name

	.EXAMPLE
		PS C:\> Get-PowerScheme

	.NOTES
		Additional information about the function.
#>

	[CmdletBinding()][OutputType([object])]
	param ()

	#Get the currently active power scheme
	$Query = Configure-Power "/getactivescheme"
	#Get the alias name of the active power scheme
	$ActiveSchemeName = ($Query.Split("()").Trim())[1]
	#Get the GUID of the active power scheme
	$ActiveSchemeGUID = ($Query.Split(":(").Trim())[1]
	$Query = Configure-Power "/query $ActiveSchemeGUID"
	try {
		$GUIDAliasLine = ($Query | where { $_.Contains("GUID Alias:") }).Split(":")[1].Trim()
		$Scheme = New-Object -TypeName PSObject
		$Scheme | Add-Member -Type NoteProperty -Name PowerScheme -Value $ActiveSchemeName
		$Scheme | Add-Member -Type NoteProperty -Name GUIDAlias -Value $GUIDAlias
		$Scheme | Add-Member -Type NoteProperty -Name GUID -Value $ActiveSchemeGUID
	}
	catch {
		Write-Warning "Get-PowerScheme failure, error may be:`n$Query"
	}
	Return $Scheme
}

function Set-PowerScheme {
<#
	.SYNOPSIS
		Set the power scheme to the specified scheme

	.DESCRIPTION
		Sets the power scheme to the specified scheme

	.PARAMETER PowerScheme
		Friendly power scheme name

	.PARAMETER CustomPowerScheme
		Create a custom power scheme

	.EXAMPLE
		PS C:\> Set-PowerScheme -PowerScheme 'Value1'

	.NOTES
		Additional information about the function.
#>

#	[CmdletBinding()][OutputType([boolean])]
	param
	(
		[string]
		$PowerScheme
	)

	#Get list of existing power schemes
	$PowerSchemesOutput = Configure-Power "/l"
	if ($null -ne $PowerScheme -and $PowerScheme -ne "") {
		Write-Host "PowerSchemes:" $PowerSchemesOutput
		Write-Host "ActivePowerScheme: $($ActivePowerScheme | fl * | Out-String)"
		Write-Host "ActivePowerScheme.PowerScheme: $($ActivePowerScheme.PowerScheme)"

		$PowerSchemePattern = '(?<Guid>(?:[0-9a-fA-F]){8}-(?:[0-9a-fA-F]){4}-(?:[0-9a-fA-F]){4}-(?:[0-9a-fA-F]){4}-(?:[0-9a-fA-F]){12})\s*\((?<SchemeName>[A-Za-z\d\s]+)\)\s*(?<Active>\*)?'
		$AllPowerSchemes = Select-String -InputObject $PowerSchemesOutput -Pattern $PowerSchemePattern  -AllMatches
		$GuidPowerSchemeToSet = $AllPowerSchemes.Matches | ?{$_.Groups['SchemeName'].Value -eq $PowerScheme} | %{$_.Groups['Guid'].Value} | Select -First 1

		if($GuidPowerSchemeToSet) {
			#Set power scheme
			$ActivePowerScheme = Get-PowerScheme
			Write-Host "Setting Power Scheme from $($ActivePowerScheme.PowerScheme) to $($PowerScheme)....." -NoNewline
			$NewActiveSchemeName = Configure-Power "/setactive $GuidPowerSchemeToSet"
		}
		$ActivePowerScheme = Get-PowerScheme
		if ($PowerScheme -eq $ActivePowerScheme.PowerScheme) {
			Write-Host "Success" -ForegroundColor Yellow
			Return $false
		} else {
			Write-Host "Failed" -ForegroundColor Red
			Return $true
		}
	}
}

Function Get-ActionIndexFromValue
{
	#Lid close Ref: https://learn.microsoft.com/en-us/windows-hardware/customize/power-settings/power-button-and-lid-settings-lid-switch-close-action
	#Power Button Ref: https://learn.microsoft.com/en-us/windows-hardware/customize/power-settings/power-button-and-lid-settings-power-button-action
	#Sleep Button Ref: https://learn.microsoft.com/en-us/windows-hardware/customize/power-settings/power-button-and-lid-settings-sleep-button-action
    param([string]$Value)
    switch($Value)
    {
        'Do Nothing'
        {
            return 0
        }
        'Sleep'
        {
            return 1
        }
        'Hibernate'
        {
            return 2
        }
        'Shut Down'
        {
            return 3
        }
    }

}

function Set-PowerSchemeSettings {
<#
	.SYNOPSIS
		Config/Validate current power scheme

	.DESCRIPTION
		This will modify settings of the currently active power scheme.

	.PARAMETER MonitorTimeoutAC
		The time until the screensaver turns on while plugged into AC outlet

	.PARAMETER MonitorTimeoutDC
		The time until the screensaver turns on while on battery power

	.PARAMETER DiskTimeoutAC
		Time that windows will wait for a hard disk to respond to a command while plugged into AC outlet

	.PARAMETER DiskTimeoutDC
		Time that windows will wait for a hard disk to respond to a command while on battery power

	.PARAMETER StandbyTimeoutAC
		Amount of time before a computer is put on standby while plugged into AC outlet

	.PARAMETER StandbyTimeoutDC
		Amount of time before a computer is put on standby while on battery power

	.PARAMETER HibernateTimeoutAC
		Amount of time before a computer is put in hibernation while plugged into AC outlet

	.PARAMETER HibernateTimeoutDC
		Amount of time before a computer is put in hibernation while on battery power

	.EXAMPLE
		PS C:\> Set-PowerSchemeSettings -MonitorTimeoutAC $value1 -MonitorTimeoutDC $value2

	.NOTES
		Additional information about the function.
#>

	# [CmdletBinding()]
	param
	(
		[switch]$Validate,
		[switch]$Config,
        [string]$MonitorTimeoutAC,
		[string]$MonitorTimeoutDC,
		[string]$DiskTimeoutAC,
		[string]$DiskTimeoutDC,
		[string]$StandbyTimeoutAC,
		[string]$StandbyTimeoutDC,
		[string]$HibernateTimeoutAC,
		[string]$HibernateTimeoutDC,
		[string]$LidCloseActionAC,
		[string]$LidCloseActionDC,
		[string]$PowerButtonActionAC,
		[string]$PowerButtonActionDC,
		[string]$SleepButtonActionAC,
		[string]$SleepButtonActionDC,
		$USBSelectiveSuspendAC,
		$USBSelectiveSuspendDC,
		$PasswordProtectWakeupAC,
		$PasswordProtectWakeupDC
	)

	$Scheme = Get-PowerScheme
	$RegArray = @()
	if ($MonitorTimeoutAC) {
		$Description = "Monitor timeout on AC in minutes....."
		$RegArray += @{
			Description = $Description
			Switches = "/change monitor-timeout-ac $MonitorTimeoutAC"
			Path = "Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes\" + $Scheme.GUID + "\7516b95f-f776-4464-8c53-06167f40cc99\3c0bc021-c8a8-4e07-a973-6b14cbcb2b7e"
			Value = $MonitorTimeoutAC
			PowerIndex = "ACSettingIndex"
		}
	}
	if ($MonitorTimeoutDC) {
		$Description = "Monitor timeout on DC in minutes....."
		$RegArray += @{
			Description = $Description
			Switches = "/change monitor-timeout-dc $MonitorTimeoutDC"
			Path = "Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes\" + $Scheme.GUID + "\7516b95f-f776-4464-8c53-06167f40cc99\3c0bc021-c8a8-4e07-a973-6b14cbcb2b7e"
			Value = $MonitorTimeoutDC
			PowerIndex = "DCSettingIndex"
		}
	}
	if ($DiskTimeoutAC) {
		$Description = "Disk timeout on AC in minutes....."
		$RegArray += @{
			Description = $Description
			Switches = "/change disk-timeout-ac $DiskTimeoutAC"
			Path = "Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes\" + $Scheme.GUID + "\0012ee47-9041-4b5d-9b77-535fba8b1442\6738e2c4-e8a5-4a42-b16a-e040e769756e"
			Value = $DiskTimeoutAC
			PowerIndex = "ACSettingIndex"
		}
	}
	if ($DiskTimeoutDC) {
		$Description = "Disk timeout on DC in minutes....."
		$RegArray += @{
			Description = $Description
			Switches = "/change disk-timeout-dc $DiskTimeoutDC"
			Path = "Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes\" + $Scheme.GUID + "\0012ee47-9041-4b5d-9b77-535fba8b1442\6738e2c4-e8a5-4a42-b16a-e040e769756e"
			Value = $DiskTimeoutDC
			PowerIndex = "DCSettingIndex"
		}
	}
	if ($StandbyTimeoutAC) {
		$Description = "Standby timeout on AC in minutes....."
		$RegArray += @{
			Description = $Description
			Switches = "/change standby-timeout-ac $StandbyTimeoutAC"
			Path = "Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes\" + $Scheme.GUID + "\238c9fa8-0aad-41ed-83f4-97be242c8f20\29f6c1db-86da-48c5-9fdb-f2b67b1f44da"
			Value = $StandbyTimeoutAC
			PowerIndex = "ACSettingIndex"
		}
	}
	if ($StandbyTimeoutDC) {
		$Description = "Standby timeout on DC in minutes....."
		$RegArray += @{
			Description = $Description
			Switches = "/change standby-timeout-dc $StandbyTimeoutDC"
			Path = "Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes\" + $Scheme.GUID + "\238c9fa8-0aad-41ed-83f4-97be242c8f20\29f6c1db-86da-48c5-9fdb-f2b67b1f44da"
			Value = $StandbyTimeoutDC
			PowerIndex = "DCSettingIndex"
		}
	}
	if ($HibernateTimeoutAC) {
		$Description = "Hibernate timeout on AC in minutes....."
		$RegArray += @{
			Description = $Description
			Switches = "/change hibernate-timeout-ac $HibernateTimeoutAC"
			Path = "Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes\" + $Scheme.GUID + "\238c9fa8-0aad-41ed-83f4-97be242c8f20\9d7815a6-7ee4-497e-8888-515a05f02364"
			Value = $HibernateTimeoutAC
			PowerIndex = "ACSettingIndex"
		}
	}
	if ($HibernateTimeoutDC) {
		$Description = "Hibernate timeout on DC in minutes....."
		$RegArray += @{
			Description = $Description
			Switches = "/change hibernate-timeout-dc $HibernateTimeoutDC"
			Path = "Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes\" + $Scheme.GUID + "\238c9fa8-0aad-41ed-83f4-97be242c8f20\9d7815a6-7ee4-497e-8888-515a05f02364"
			Value = $HibernateTimeoutDC
			PowerIndex = "DCSettingIndex"
		}
	}
    if ($LidCloseActionAC) {
		$Index = Get-ActionIndexFromValue $LidCloseActionAC
		$Description = "Lid close action on AC....."
		$RegArray += @{
			Description = $Description
			Switches = "/setacvalueindex $($Scheme.GUID) 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 $Index"
			Path = "Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes\" + $Scheme.GUID + "\4f971e89-eebd-4455-a8de-9e59040e7347\5ca83367-6e45-459f-a27b-476b1d01c936"
			Value = $Index
			PowerIndex = "ACSettingIndex"
		}
	}
	if ($LidCloseActionDC) {
		$Index = Get-ActionIndexFromValue $LidCloseActionDC
		$Description = "Lid close action on DC....."
		$RegArray += @{
			Description = $Description
			Switches = "/setdcvalueindex $($Scheme.GUID) 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 $Index"
			Path = "Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes\" + $Scheme.GUID + "\4f971e89-eebd-4455-a8de-9e59040e7347\5ca83367-6e45-459f-a27b-476b1d01c936"
			Value = $Index
			PowerIndex = "DCSettingIndex"
		}
	}

	if ($PowerButtonActionAC) {
		$Index = Get-ActionIndexFromValue $PowerButtonActionAC
		$Description = "Power Button action on AC....."
		$RegArray += @{
			Description = $Description
			Switches = "/setacvalueindex $($Scheme.GUID) 4f971e89-eebd-4455-a8de-9e59040e7347 7648efa3-dd9c-4e3e-b566-50f929386280 $Index"
			Path = "Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes\" + $Scheme.GUID + "\4f971e89-eebd-4455-a8de-9e59040e7347\7648efa3-dd9c-4e3e-b566-50f929386280"
			Value = $Index
			PowerIndex = "ACSettingIndex"
		}
	}
	if ($PowerButtonActionDC) {
		$Index = Get-ActionIndexFromValue $PowerButtonActionDC
		$Description = "Power Button action on DC....."
		$RegArray += @{
			Description = $Description
			Switches = "/setdcvalueindex $($Scheme.GUID) 4f971e89-eebd-4455-a8de-9e59040e7347 7648efa3-dd9c-4e3e-b566-50f929386280 $Index"
			Path = "Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes\" + $Scheme.GUID + "\4f971e89-eebd-4455-a8de-9e59040e7347\7648efa3-dd9c-4e3e-b566-50f929386280"
			Value = $Index
			PowerIndex = "DCSettingIndex"
		}
	}

	if ($SleepButtonActionAC) {
		$Index = Get-ActionIndexFromValue $SleepButtonActionAC
		$Description = "Sleep Button action on AC....."
		$RegArray += @{
			Description = $Description
			Switches = "/setacvalueindex $($Scheme.GUID) 4f971e89-eebd-4455-a8de-9e59040e7347 96996bc0-ad50-47ec-923b-6f41874dd9eb $Index"
			Path = "Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes\" + $Scheme.GUID + "\4f971e89-eebd-4455-a8de-9e59040e7347\96996bc0-ad50-47ec-923b-6f41874dd9eb"
			Value = $Index
			PowerIndex = "ACSettingIndex"
		}
	}
	if ($SleepButtonActionDC) {
		$Index = Get-ActionIndexFromValue $SleepButtonActionDC
		$Description = "Sleep Button action on DC....."
		$RegArray += @{
			Description = $Description
			Switches = "/setdcvalueindex $($Scheme.GUID) 4f971e89-eebd-4455-a8de-9e59040e7347 7648efa3-dd9c-4e3e-b566-50f929386280 $Index"
			Path = "Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes\" + $Scheme.GUID + "\4f971e89-eebd-4455-a8de-9e59040e7347\96996bc0-ad50-47ec-923b-6f41874dd9eb"
			Value = $Index
			PowerIndex = "DCSettingIndex"
		}
	}

    if ($null -ne $USBSelectiveSuspendAC) {
		$Index = [int][bool]$USBSelectiveSuspendAC
		$Description = "USB Selective Suspend on AC....."
		$RegArray += @{
			Description = $Description
			Switches = "/setacvalueindex $($Scheme.GUID) 2a737441-1930-4402-8d77-b2bebba308a3 48e6b7a6-50f5-4782-a5d4-53bb8f07e226 $Index"
			Path = "Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes\" + $Scheme.GUID + "\2a737441-1930-4402-8d77-b2bebba308a3\48e6b7a6-50f5-4782-a5d4-53bb8f07e226"
			Value = $Index
			PowerIndex = "ACSettingIndex"
		}
	}
	if ($null -ne $USBSelectiveSuspendDC) {
		$Index = [int][bool]$USBSelectiveSuspendDC
		$Description = "USB Selective Suspend on DC....."
		$RegArray += @{
			Description = $Description
			Switches = "/setdcvalueindex $($Scheme.GUID) 2a737441-1930-4402-8d77-b2bebba308a3 48e6b7a6-50f5-4782-a5d4-53bb8f07e226 $Index"
			Path = "Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes\" + $Scheme.GUID + "\2a737441-1930-4402-8d77-b2bebba308a3\48e6b7a6-50f5-4782-a5d4-53bb8f07e226"
			Value = $Index
			PowerIndex = "DCSettingIndex"
		}
	}


	if($null -ne $PasswordProtectWakeupAC)
	{
		$Value = [int][bool]$PasswordProtectWakeupAC
		$Description = "PasswordProtectWakeup on AC to $Value....."
		$RegArray += @{
			Description = $Description
			Switches = "/setacvalueindex $($Scheme.GUID) SUB_NONE CONSOLELOCK $Value"
			Path = "Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes\" + $Scheme.GUID + "\0E796BDB-100D-47D6-A2D5-F7D2DAA51F51"
			Value = $Value
			PowerIndex = "ACSettingIndex"
		}
	}
	if($null -ne $PasswordProtectWakeupDC)
	{
		$Value = [int][bool]$PasswordProtectWakeupDC
		$Description = "PasswordProtectWakeup on DC to $Value....."
		$RegArray += @{
			Description = $Description
			Switches = "/setdcvalueindex $($Scheme.GUID) SUB_NONE CONSOLELOCK $Value"
			Path = "Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes\" + $Scheme.GUID + "\0E796BDB-100D-47D6-A2D5-F7D2DAA51F51"
			Value = $Value
			PowerIndex = "DCSettingIndex"
		}
	}

	$ValidateResult = $true
	foreach($Setting in $RegArray)
	{
    	#Write-Host ($Setting | fl * | Out-String)
		if ($Config -eq $true)
		{
			Write-Host "Setting $($Setting.Description)" -NoNewLine
			Configure-Power $Setting.Switches
		}

		if (Test-Path $Setting.Path -ErrorAction SilentlyContinue)
		{
			Write-Host "Testing $($Setting.Path) $($Setting.PowerIndex)"
			$RegValue = Get-ItemProperty $Setting.Path -Name $Setting.PowerIndex -ErrorAction SilentlyContinue | %{$_."$($Setting.PowerIndex)"}
			Write-Host "RegValue: $RegValue"
			# if(!(!([string]::IsNullOrEmpty($USBSelectiveSuspendDC) -or ![string]::IsNullOrEmpty($LidCloseActionAC))))
			if($Setting.Description -notmatch "PasswordProtectWakeup|Lid close action|Power Button action|Sleep Button action|USB Selective Suspend")
			{
				$RegValue /= 60
			}
			#Round down to the nearest tenth due to hibernate values being 1 decimal off
			#$RegValue = $RegValue - ($RegValue % 10)
		}
		else
		{
			Write-Warning "Path does not exist: $($Setting.Path)"
			$RegValue = $null
		}

		if ($Validate -eq $true)
		{
			Write-Host "Validating $($Setting.Description). Expecting $($Setting.Value) found $RegValue. " -NoNewLine
			if (($null -eq $RegValue) -or ($Setting.Value -ne $RegValue))
			{
				if($null -eq $RegValue)
				{
					$RegValue = "null"
				}
				elseif('' -eq $RegValue)
				{
					$RegValue = "Empty String"
				}
				Write-Warning "Expected $($Setting.Value) Found $RegValue"
				$ValidateResult = $false
			}
			#DR 20230815, the foreach is testing multiple values, you can't just return on the first match!
			#Write-Host "Values Match, returning $true"
			#return $true
		}
	}
	# In case no values were tested
	return $ValidateResult
}

$CurrentPowerScheme = Get-PowerScheme
$TestResult = ($null -ne $PlanName -and $null -ne $CurrentPowerScheme -and $CurrentPowerScheme.PowerScheme -eq $PlanName)
$TestResult = (Set-PowerSchemeSettings -Validate -MonitorTimeoutAC $MonitorTimeoutAC ) -and $TestResult
$TestResult = (Set-PowerSchemeSettings -Validate -MonitorTimeoutDC $MonitorTimeoutDC ) -and $TestResult
$TestResult = (Set-PowerSchemeSettings -Validate -DiskTimeOutAC $DiskTimeOutAC ) -and $TestResult
$TestResult = (Set-PowerSchemeSettings -Validate -DiskTimeOutDC $DiskTimeOutDC ) -and $TestResult
$TestResult = (Set-PowerSchemeSettings -Validate -StandbyTimeoutAC $StandbyTimeoutAC ) -and $TestResult
$TestResult = (Set-PowerSchemeSettings -Validate -StandbyTimeoutDC $StandbyTimeoutDC ) -and $TestResult
$TestResult = (Set-PowerSchemeSettings -Validate -HibernateTimeoutAC $HibernateTimeoutAC ) -and $TestResult
$TestResult = (Set-PowerSchemeSettings -Validate -HibernateTimeoutDC $HibernateTimeoutDC) -and $TestResult
$TestResult = (Set-PowerSchemeSettings -Validate -LidCloseActionAC $LidCloseActionAC) -and $TestResult
$TestResult = (Set-PowerSchemeSettings -Validate -LidCloseActionDC $LidCloseActionDC) -and $TestResult
$TestResult = (Set-PowerSchemeSettings -Validate -PowerButtonActionAC $PowerButtonActionAC) -and $TestResult
$TestResult = (Set-PowerSchemeSettings -Validate -PowerButtonActionDC $PowerButtonActionDC) -and $TestResult
$TestResult = (Set-PowerSchemeSettings -Validate -SleepButtonActionAC $SleepButtonActionAC) -and $TestResult
$TestResult = (Set-PowerSchemeSettings -Validate -SleepButtonActionDC $SleepButtonActionDC) -and $TestResult
$TestResult = (Set-PowerSchemeSettings -Validate -USBSelectiveSuspendAC $USBSelectiveSuspendAC) -and $TestResult
$TestResult = (Set-PowerSchemeSettings -Validate -USBSelectiveSuspendDC $USBSelectiveSuspendDC) -and $TestResult
$TestResult = (Set-PowerSchemeSettings -Validate -PasswordProtectWakeupAC $PasswordProtectWakeupAC) -and $TestResult
$TestResult = (Set-PowerSchemeSettings -Validate -PasswordProtectWakeupDC $PasswordProtectWakeupDC) -and $TestResult

 switch ($method) {
	"set" {
	     $PlanExists = $false
	     Write-Host "PlanName: $PlanName"
         #Check if $PlanName already exists and make it as active
         $perf = Configure-Power "-l" | %{
			if($_ -like "*$PlanName*") {
				Write-Host "$PlanName already exists"
				$PlanExists = $true
				Set-PowerScheme $PlanName
			}
		}
         #if $PlanName does not exist Create it and set as active
		if (-NOT ($PlanExists)) {
			Write-Host "Create Plan based on currently active power scheme"
			#Get the currently active power scheme
			$Query = Configure-Power "/getactivescheme"
			#Get the alias name of the active power scheme
			$ActiveSchemeName = ($Query.Split("()").Trim())[1]
			#Get the GUID of the active power scheme
			$ActiveSchemeGUID = ($Query.Split(":(").Trim())[1]
			Write-Host "ActiveSchemeName:" $ActiveSchemeName
			Write-Host "ActiveSchemeGUID:" $ActiveSchemeGUID

			#Duplicate currently active power scheme
			$QueryDuplicatedScheme = Configure-Power "/duplicatescheme $ActiveSchemeGUID"
			#Get the alias name of DUPLICATED power scheme
			$DuplicatedSchemeName = ($QueryDuplicatedScheme.Split("()").Trim())[1]
			#Get the GUID of DUPLICATED power scheme
			$DuplicatedSchemeGUID = ($QueryDuplicatedScheme.Split(":(").Trim())[1]
			Write-Host "DUPLICATED SchemeName:" $DuplicatedSchemeName
			Write-Host "DUPLICATED SchemeGUID:" $DuplicatedSchemeGUID
			#Change Name for DUPLICATED power scheme to $PlanName and set it as Active
			$QueryCustomScheme = Configure-Power "/changename $DuplicatedSchemeGUID ""$PlanName"""
			$NewActiveSchemeName = Configure-Power "/setactive $DuplicatedSchemeGUID"
		}
        #Set new power scheme's settings
        Set-PowerSchemeSettings -Config -MonitorTimeoutAC $MonitorTimeoutAC
        Set-PowerSchemeSettings -Config -MonitorTimeoutDC $MonitorTimeoutDC
        Set-PowerSchemeSettings -Config -DiskTimeOutAC $DiskTimeOutAC
        Set-PowerSchemeSettings -Config -DiskTimeOutDC $DiskTimeOutDC
        Set-PowerSchemeSettings -Config -StandbyTimeoutAC $StandbyTimeoutAC
        Set-PowerSchemeSettings -Config -StandbyTimeoutDC $StandbyTimeoutDC
        Set-PowerSchemeSettings -Config -HibernateTimeoutAC $HibernateTimeoutAC
        Set-PowerSchemeSettings -Config -HibernateTimeoutDC $HibernateTimeoutDC
        Set-PowerSchemeSettings -Config -LidCloseActionAC $LidCloseActionAC
        Set-PowerSchemeSettings -Config -LidCloseActionDC $LidCloseActionDC
				Set-PowerSchemeSettings -Config -PowerButtonActionAC $PowerButtonActionAC
        Set-PowerSchemeSettings -Config -PowerButtonActionDC $PowerButtonActionDC
				Set-PowerSchemeSettings -Config -SleepButtonActionAC $SleepButtonActionAC
        Set-PowerSchemeSettings -Config -SleepButtonActionDC $SleepButtonActionDC
        Set-PowerSchemeSettings -Config -USBSelectiveSuspendAC $USBSelectiveSuspendAC
        Set-PowerSchemeSettings -Config -USBSelectiveSuspendDC $USBSelectiveSuspendDC
        Set-PowerSchemeSettings -Config -PasswordProtectWakeupAC $PasswordProtectWakeupAC
        Set-PowerSchemeSettings -Config -PasswordProtectWakeupDC $PasswordProtectWakeupDC
    	Configure-Power "/setactive scheme_current"
        #Keep it to have a possibility for roll-back action - to Reset PowerScheme to one of Standart:
        #Set-PowerScheme -PowerScheme 'Balanced' #Set the Power Scheme to Balanced
        #Set-PowerScheme -PowerScheme 'Power Saver' #Set the Power Scheme to Power Saver
        #Set-PowerScheme -PowerScheme 'High Performance' #Set the Power Scheme to High Performance
	}
	"test" {
	    if($TestResult -eq $false){
			Write-Warning "If Group policy override settings exist for power options, it may block changes and force noncompliance"
			return $TestResult
		}
		else{
			return $TestResult
		}
	}
}

@TerryW you wanna have a peek at this one? Couple of goodies we might could add here :smile: