i am the funny
 

 I AM THE FUNNY!!!

Ok, so the battery on my laptop is dying so it does stupid things and I don't always get a warning to plug in the power. Hence the script. Enjoy...

Added some updates, like changing the size of the powershell window, making it so you can shut down when battery is low... and that's it :)

# Set up the voice stuff
Add-Type -AssemblyName System.Speech
$object = New-Object System.Speech.Synthesis.SpeechSynthesizer
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") 

#------------------------------------------------------------------
# Changes the size of the powershell window
#------------------------------------------------------------------
$pshost = Get-Host # Get the PowerShell Host.
$pswindow = $pshost.UI.RawUI # Get the PowerShell Host's UI.

$newsize = $pswindow.windowsize # Get the UI's current Window Size.
$newsize.width = 62 # Set the new Window Width to 24 columns.
$newsize.height = 18 # Set the new Window Height to 2 rows.
$pswindow.windowsize = $newsize # Set the new Window Size as active.

$newsize = $pswindow.BufferSize # Get the UI's current Buffer Size.
$newsize.width = 62 # Set the new buffer's width to 24 columns.
$newsize.height = 18 # Set the new buffer's height to 2 rows.
$pswindow.buffersize = $newsize # Set the new Buffer Size as active.

Function Show-Menu([string]$Title){
     cls
     Write-Host "=================== $Title ==================="
     
     Write-Host "1: Press '1' Laptop not plugged in."
     Write-Host "2: Press '2' Laptop Charging."
     Write-Host "3: Press '3' Shutdown laptop when charge too low."
     Write-Host "Q: Press 'Q' to quit."
     Write-Host "`nNOTE: Make sure that your sound is turned on.`nOtherwise you won't hear the warning.`n`n" -ForegroundColor Red
}

Function BatteryLife{
    $Battery = Get-WmiObject -Class Win32_Battery
    [int]$BRunTime = $Battery.EstimatedRunTime
    [int]$BPercent = $Battery.EstimatedChargeRemaining
    switch ($BRunTime){
        {$_ -eq 71582788}{
            write-host -NoNewline "Power is plugged in" -ForegroundColor Magenta
        }
        {90..10000 -contains $_}{
            write-host -NoNewline "$BRunTime minutes left" -ForegroundColor Cyan
            }
        {60..89 -contains $_}{
            write-host -NoNewline "$BRunTime minutes left" -ForegroundColor Green
            }
        {30..59 -contains $_}{
            write-host -NoNewline "$BRunTime minutes left" -ForegroundColor yellow
            }
        {20..29 -contains $_}{
            write-host -NoNewline "$BRunTime minutes left" -ForegroundColor DarkRed
            }
        {1..19 -contains $_}{
            write-host -NoNewline "$BRunTime minutes left" -ForegroundColor Red
            }
    }
    
    write-host -NoNewline " - " -ForegroundColor White

    switch ($BPercent){
        {$_ -gt 59}{
            write-host -NoNewline "$BPercent percent left" -ForegroundColor Green
            }
        {30..59 -contains $_}{
            write-host -NoNewline "$BPercent percent left" -ForegroundColor yellow
            }
        {20..29 -contains $_}{
            write-host -NoNewline "$BPercent percent left" -ForegroundColor DarkRed
            }
        {1..19 -contains $_}{
            write-host -NoNewline "$BPercent percent left" -ForegroundColor Red
            }
    }
    write-host
    start-sleep -s 10
    if($BRunTime -eq 71582788){
        if($BPercent -ge 100){
            $x = 3
        }else{$x = 2}
    }elseif(($BRunTime -lt 20) -or ($BPercent -lt 20)){
        $x = 1
    }else{$x = 10}

    return $x

}

do{
    Show-Menu "Battery Charge Checker"
    $input = Read-Host "Please make a selection"
    cls
    Switch ($input) {
        "1" {
            Do{
                $result = BatteryLife
            }Until($result -eq 1)
            Do{
                $object.Speak("Plug in the power!!!")
                $result = BatteryLife
            }Until($result -eq 2)
        }
        "2" {
            $leaveItIn = 0
           Do{
                $result = BatteryLife
            }Until($result -eq 3)
            Do{
                $result = BatteryLife
                $object.Speak("You can unplug the power now.")
                # extra sleep time in case i am away
                $leaveItIn++
                write-host $leaveItIn
                start-sleep -s 50
                if($leaveItIn -eq 5){
                    $question = [System.Windows.Forms.MessageBox]::Show("Do you qant to stop the check?", "I am question", 4, 32)
                    If($question -eq "YES"){
                        $result=10
                        Write-host "Exiting Script"
                    }Else{start-sleep -Seconds 3600}
                }

            }Until($result -eq 10)
        }
        "3" {
            Do{
                $result = BatteryLife
            }Until($result -eq 1)
            $object.Speak("Shutting down")
            Stop-Computer -force
        }
        "q" {
            Write-host "Quitting now"
            sleep -s 2
        }
    }
}until ($input -eq 'q')