This script monitors your laptop's battery usage and tracks how long the battery lasts on a single charge, with smart pause/resume functionality.
- Smart Timer: Starts when unplugged at 97%+ battery
- Intelligent Pause/Resume: Pauses when charging, resumes only after draining to previous percentage
- Auto-Reset: Resets timer when charging above 90%
- Notifications: Windows toast notifications with sound alerts
- Data Logging: Saves battery backup records to CSV file
- Average Calculation: Tracks average battery backup duration
BatteryMonitor.ps1- Main monitoring scriptRunBatteryMonitor.bat- Batch file to run the scriptSetupAutoStart.ps1- Sets up automatic startupTestBatteryMonitor.ps1- Tests all functionsREADME.md- This file
# Right-click on TestBatteryMonitor.ps1 and "Run with PowerShell"
# This will verify everything is working# Right-click on SetupAutoStart.ps1 and "Run as Administrator"
# This creates a Windows Task that runs on every login# To test manually, right-click on BatteryMonitor.ps1 and "Run with PowerShell"
# Or double-click RunBatteryMonitor.bat- Start: Unplug charger at 97%+ battery → Timer starts
- Pause: Plug in between 20-89% → Timer pauses
- Resume: Unplug again → Timer waits until battery drains to previous percentage
- Reset: Charge above 90% → Timer resets completely
- Complete: Connect charger below 10% → Saves recording
The script uses these thresholds (you can modify in the script):
- Full Battery: 97% (triggers timer start)
- Low Battery: 10% (saves recording)
- Pause Range: 20-89% (timer pauses when charging)
- Reset Threshold: 90% (timer resets when charging above this)
- Disconnect Notification: 90% (reminds you to unplug)
All data is saved to: Documents\BatteryBackup\
battery_backup_records.csv- Individual backup sessionsbattery_backup_average.txt- Average backup duration
- Check Windows notification settings
- Ensure "Focus Assist" is not blocking notifications
- Check PowerShell execution policy:
Get-ExecutionPolicy - If restricted, run:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
- Run
SetupAutoStart.ps1as Administrator - Check Task Scheduler:
taskschd.msc - Look for "BatteryMonitor" task
To verify it's working:
- Check Task Manager: Look for PowerShell processes
- Check Logs: Look for files in
Documents\BatteryBackup\ - Check Notifications: You should see notifications when conditions are met
- Check Console: If running manually, you'll see real-time status
If you encounter issues:
- Run
TestBatteryMonitor.ps1first - Check the console output for error messages
- Verify all files are in the correct location
- Ensure PowerShell execution policy allows script execution