Battery-Notification

Seamless Battery Monitoring: Full Charge & Low Battery Alerts for Windows

Tired of accidentally overcharging your laptop or letting the battery die? This PowerShell script provides continuous, audible alerts for both low battery and full charge states, and is configured to start automatically every time you log into Windows.


💡 Script Features & Configuration

FeatureDescriptionDefault Setting
Low Battery AlertTriggers an audible alert when the charger is unplugged.19% or below
Full Charge AlertTriggers an audible alert when the charger is plugged in.100%
Monitoring IntervalHow often the script checks the battery status.Every 15 seconds
Audible AlertRequires a .wav file to play the sound.C:\Script\Alert.wav

⚙️ Step 1: Preparation – Setup and Sound File

Before running the script, you must create a folder and place your sound alert file there.

  1. Create the Folder: Create a new folder named Script directly on your C: drive.
    • Required Path: C:\Script
  2. Get a .wav Alert: Find a short, attention-grabbing .wav sound file.
  3. Place the File: Save the .wav file inside the C:\Script folder and rename it to Alert.wav.

⚠️ Configuration Check: If the script cannot find C:\Script\Alert.wav, it will fail to start.


📝 Step 2: The PowerShell Script (Save as .ps1)

Save the following code block as a plain text file named BatteryMonitor.ps1 inside your C:\Script folder.

PowerShell

<#
.SYNOPSIS
    (DEBUG VERSION) Monitors the laptop battery for low or full states and provides
    verbose output for diagnostics.

.DESCRIPTION
    This script runs continuously to monitor battery status every 15 seconds.
    It includes a debug line that prints the current charge percentage and power
    status on each check to help diagnose why alerts may not be triggering.

    - Low Battery Warning: Triggers at or below 19% when unplugged.
    - Full Charge Alert: Triggers at 100% when plugged in.
#>

# --- Configuration ---
$soundFilePath = "C:\Script\Alert.wav"
$lowBatteryThreshold = 19

# --- Initialization and Validation ---
if (-not (Test-Path -Path $soundFilePath)) {
    Write-Error "Fatal: Sound file not found at '$soundFilePath'. Please check the path."
    Start-Sleep -Seconds 10
    exit 1
}

$soundPlayer = New-Object System.Media.SoundPlayer($soundFilePath)

# --- Main Logic ---
Write-Host "Initializing Dual-Condition Battery Monitor (DEBUG MODE)..."
Write-Host " - Low battery warning will trigger at $($lowBatteryThreshold)% or below (when unplugged)."
Write-Host " - Full charge alert will trigger at 100% (when plugged in)."
Write-Host "Press Ctrl+C in this terminal to stop the script."

# Primary monitoring loop
while ($true) {
    try {
        $battery = Get-CimInstance -ClassName Win32_Battery
        $chargePercentage = $battery.EstimatedChargeRemaining
        $batteryStatusCode = $battery.BatteryStatus
        $isPluggedIn = ($batteryStatusCode -ne 1)

 
        # This line prints the live status on every check.
        Write-Host "$(Get-Date -Format 'HH:mm:ss') - Monitoring: Charge = $chargePercentage%, PluggedIn = $isPluggedIn (Status Code: $batteryStatusCode)"

        # --- Condition 1: Low Battery Warning ---
        if ($chargePercentage -le $lowBatteryThreshold -and -not $isPluggedIn) {
            Write-Host "$(Get-Date): ACTIVATING LOW BATTERY WARNING. Charge: $chargePercentage%."
            while ($true) {
                $soundPlayer.PlaySync()
                $currentStatus = (Get-CimInstance -ClassName Win32_Battery).BatteryStatus
                if ($currentStatus -ne 1) {
                    Write-Host "$(Get-Date): Charger connected. Stopping warning."
                    break
                }
            }
            Write-Host "$(Get-Date): Warning stopped. Resuming monitoring."
        }
        # --- Condition 2: Full Charge Alert ---
        elseif ($chargePercentage -eq 100 -and $isPluggedIn) {
            Write-Host "$(Get-Date): ACTIVATING FULL CHARGE ALERT. Charge: 100%."
            while ($true) {
                $soundPlayer.PlaySync()
                $currentStatus = (Get-CimInstance -ClassName Win32_Battery).BatteryStatus
                if ($currentStatus -eq 1) {
                    Write-Host "$(Get-Date): Charger disconnected. Stopping alert."
                    break
                }
            }
            Write-Host "$(Get-Date): Alert stopped. Resuming monitoring."
        }
    }
    catch {
        Write-Warning "An error occurred while checking battery status: $_"
    }

    # Wait for 15 seconds before the next check.
    Start-Sleep -Seconds 15
}

🚀 Step 3: Configure Automatic Startup via Task Scheduler

To run the PowerShell script without the console window showing, we’ll use a tiny VBScript file to launch it silently.

A. Create the VBScript Wrapper

  1. Open Notepad (or any plain text editor).
  2. Paste the following two lines of code exactly as they appear:VBScriptCreateObject("WScript.Shell").Run "powershell.exe -NoProfile -ExecutionPolicy Bypass -File ""C:\Script\BatteryMonitor.ps1""", 0, True 💡 Note: The 0 near the end is the key—it tells the Windows Script Host to launch the command in a hidden window.
  3. Save the file in your C:\Script folder as SilentLauncher.vbs.

B. Update Task Scheduler

Now, we’ll modify the Task Scheduler entry to run this VBScript wrapper instead of calling powershell.exe directly.

  1. Open Task Scheduler (Press Win + R, type taskschd.msc, and press Enter).
  2. Right-click your existing task, Battery Monitor Startup, and select Properties.
  3. Go to the Actions tab, select the existing action, and click Edit…
  4. Change the Action Configuration:
SettingOld ValueNew Value
ActionStart a programStart a program
Program/scriptpowershell.exewscript.exe
Add arguments (optional)-NoProfile -ExecutionPolicy Bypass -File "C:\Script\BatteryMonitor.ps1""C:\Script\SilentLauncher.vbs"
  1. Click OK twice to save the changes. Task Scheduler may prompt you for your password again.

C. Final Test

  • Reboot your computer.
  • The script should now start automatically after you log in, and no PowerShell window will appear.
  • To confirm it’s running, you can open the Task Manager (Ctrl+Shift+Esc), go to the Details tab, and look for powershell.exe running under your username. You will hear the sound alert when the battery conditions (low or full) are met.