The Categorizer

the categorizer logo

Change Power Mode/Plan In Windows (PowerShell Script)


PowerShell Script (.ps1)

# Scripts Library - TheCategorizer.com

$list = powercfg /list
$guid = @()
$mode = @()
$keys = @()
$hash_table = @{}

$config = $list[3..($list.Length - 1)]

Write-Host "Key" "" "Power Mode"
for ($i = 0; $i -lt $config.Count; $i++) {
    $guid += $config[$i].Substring(19, 36)
    $mode += $config[$i].Substring(57)
    $keys += ($i + 1)
    
    $hash_table += [ordered]@{($i) = $mode[$i] }
    
    Write-Host ($i + 1) "  " $hash_table[$i]
}

Write-Host ""
Write-Host "Choose Key"
$user_input = Read-Host

if ($user_input -in $keys) {
    Write-Host ""
    Write-Host You'''ve' chosen $user_input',' setting $hash_table[$user_input - 1]
    powercfg /setactive $guid[$user_input - 1]
    
    $active = powercfg /getactivescheme
    Write-Host Success: $active
    Pause
}

else {
    Write-Host Invalid Key!
    Pause
}

More Scripts


More Articles