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
| Feature | Description | Default Setting |
| Low Battery Alert | Triggers an audible alert when the charger is unplugged. | 19% or below |
| Full Charge Alert | Triggers an audible alert when the charger is plugged in. | 100% |
| Monitoring Interval | How often the script checks the battery status. | Every 15 seconds |
| Audible Alert | Requires 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.
- Create the Folder: Create a new folder named
Scriptdirectly on your C: drive.- Required Path:
C:\Script
- Required Path:
- Get a
.wavAlert: Find a short, attention-grabbing.wavsound file. - Place the File: Save the
.wavfile inside theC:\Scriptfolder and rename it toAlert.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
- Open Notepad (or any plain text editor).
- Paste the following two lines of code exactly as they appear:VBScript
CreateObject("WScript.Shell").Run "powershell.exe -NoProfile -ExecutionPolicy Bypass -File ""C:\Script\BatteryMonitor.ps1""", 0, True💡 Note: The0near the end is the key—it tells the Windows Script Host to launch the command in a hidden window. - Save the file in your
C:\Scriptfolder asSilentLauncher.vbs.
B. Update Task Scheduler
Now, we’ll modify the Task Scheduler entry to run this VBScript wrapper instead of calling powershell.exe directly.
- Open Task Scheduler (Press Win + R, type
taskschd.msc, and press Enter). - Right-click your existing task,
Battery Monitor Startup, and select Properties. - Go to the Actions tab, select the existing action, and click Edit…
- Change the Action Configuration:
| Setting | Old Value | New Value |
| Action | Start a program | Start a program |
| Program/script | powershell.exe | wscript.exe |
| Add arguments (optional) | -NoProfile -ExecutionPolicy Bypass -File "C:\Script\BatteryMonitor.ps1" | "C:\Script\SilentLauncher.vbs" |
- 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.exerunning under your username. You will hear the sound alert when the battery conditions (low or full) are met.




