I just did this one today - it executes command “powercfg /batteryreport”. It gets the output of the command in xml, and then navigates the xml to get the battery info. I can’t take credit for the script…I found the bulk of it online, and just tweaked it a little. Helpful to anyone?
$xmlPath = "C:\Temp\batteryreport.xml"
powercfg /batteryreport /XML /OUTPUT $xmlPath
[xml]$xmlReport = Get-Content $xmlPath
$Battery = $xmlReport.BatteryReport.Batteries.Battery
if ($Battery) {
$Design = [int64]$Battery.DesignCapacity
$Full = [int64]$Battery.FullChargeCapacity
$Pct = [math]::round(($Full / $Design) * 100, 2)
Write-Host ""
Write-Host "Battery Health: $Pct%" -ForegroundColor Green
Write-Host "Design Capacity: $Design mWh"
Write-Host "Full Charge Capacity: $Full mWh"
Write-Host ""
} else {\
Write-Host ""
Write-Host "No battery detected." -ForegroundColor Red
Write-Host ""
}
Remove-Item $xmlPath -Force