Worried about your laptop battery degradation? BatteryHealth is a lightweight PowerShell script that instantly reports your battery's actual health percentage, cycle count, and estimated runtime all by parsing Windows' built-in battery report.
GitHub Repo: https://github.com/NSTechBytes/BatteryHealth
The Problem
Over time, laptop batteries degrade. But how do you know how much your battery has degraded? You could dig through Windows settings, install third-party battery apps, or pay for specialized tools. Or... you could use this simple script that leverages Windows' own battery diagnostics.
The Solution
BatteryHealth is a lightweight PowerShell script that:
- ✅ Generates Windows' official battery report (
powercfg /batteryreport) - ✅ Parses the HTML report to extract key metrics
- ✅ Calculates battery health % (Full Charge Capacity ÷ Design Capacity)
- ✅ Displays cycle count and estimated battery life
- ✅ Color-codes the results (green for healthy, yellow for fair, red for degraded)
- ✅ Opens the full HTML report for detailed analysis
No admin rights required. No external dependencies. Pure PowerShell.
What You'll See
===== Battery Health Report =====
Design Capacity: 64000 mWh
Full Charge Capacity: 58800 mWh
Cycle Count: 187
Battery Health: 91.9%
Estimated battery life (since OS install):
At full charge: 8:30:22 (h:mm:ss)
At design capacity: 9:15:45 (h:mm:ss)
Full HTML report saved at: C:\Users\YourName\AppData\Local\Temp\battery-report.html
Opening report in default browser...
Press any key to exit...
Quick Start
- Download or clone the script:
git clone https://github.com/NSTechBytes/BatteryHealth.git
cd BatteryHealth
- Run it:
.\BatteryHealth.ps1
- View the results in your console and the full HTML report in your browser.
Why This Script?
-
Trustworthy: Uses Microsoft's own recommended battery diagnostics tool (
powercfg) - Fast: Runs in seconds
- No bloat: ~150 lines of well-commented PowerShell
- Works everywhere: Windows 10, Windows 11, any laptop with a battery
- Open source: MIT licensed, fully transparent
Key Features
Battery Health Percentage
Instantly know if your battery is still healthy (80%+), fair (50-79%), or degraded (<50%).
Robust HTML Parsing
The script handles tricky edge cases like newlines inside HTML cells that could break naive regex patterns.
Cycle Count Tracking
See how many charge/discharge cycles your battery has gone through.
Estimated Runtime
Get a realistic estimate of how long your laptop will run on battery since the OS was installed.
Beautiful Output
Color-coded console output makes it easy to spot issues at a glance.
Use Cases
- 📊 Device health checks before buying a used laptop
- 🔋 Warranty claims — get hard numbers to back them up
- 💼 Corporate IT — audit fleet battery health
- 🛠️ Troubleshooting — determine if slowdowns are battery-related
- 📈 Personal tracking — monitor your battery degradation over time
Technical Details
The script:
- Calls
powercfg /batteryreportto generate an official Windows battery report - Parses the HTML using regex to extract Design Capacity, Full Charge Capacity, and Cycle Count
- Calculates health percentage = (Full Charge ÷ Design Capacity) × 100
- Displays results with intelligent color-coding
- Opens the full report in your default browser for deep dives
Get Started
Star the repo and give it a try:
👉 https://github.com/NSTechBytes/BatteryHealth
Questions? Issues? PRs welcome!
About the Author
Created by nstechbytes a developer who believes in simple, practical tools.
Top comments (0)