Getting Battery Health With PowerShell

Getting Battery Health With PowerShell

If you want to see an overview of your battery health, the easiest way is with powercfg:

powercfg /batteryreport /output batteryreport.html
.\batteryreport.html

The above commands will generate and then open a Battery Report showing a ton of information about your battery health.

If you want to be able to more programatically work with the information, you can output the report as XML

powercfg /batteryreport /xml /output batteryreport.xml
$battery = [xml](Get-Content batteryreport.xml)

Now the $battery variable is populated with the battery report. There's a ton of useful information, so explore the $battery.BatteryReport object to find the pieces you want.

A complete script

powercfg /batteryreport /xml /output batteryreport.xml
$battery = [xml](Get-Content batteryreport.xml)
$health = [pscustomobject]@{
	time = $battery.BatteryReport.ReportInformation.ScanTime;
    maxpower = $battery.BatteryReport.Batteries.Battery.FullChargeCapacity;
    design = $battery.BatteryReport.Batteries.Battery.DesignCapacity
}
$health | Format-Table
Write-Host "Max battery capacity is only $($health.maxpower / $health.design * 100)% of designed capacity"