How to Get Windows Battery Cycle Count Using PowerShell

Introduction

PowerShell enables us to automate many things including getting battery cycle count. Rather than navigating Windows Explorer to find information about battery, automating using PowerShell must be easier and helpful.

In this article, we’ll walk through how to get battery cycle count using PowerShell.

Solution

Commands used in these solutions are only available in Windows platform, thus you can’t use the commands to get the same information in MacOs or Linux.

Using CimCmdlets

You can use Get-CimInstance then specify the namespace as well as the class as follows:


(Get-CimInstance -Namespace 'root\wmi'  -Class MSBatteryClass).CycleCount

Without specifying CycleCount property, you will get information as in below image:

get battery cycle count

In addtition to above command, there are some related useful commands as well.

To get the list of namespace available under the Root namespace on a WMI server, you can use this command:


Get-CimInstance -Namespace root -ClassName __Namespace

To get all class under specific namespace, you can use this command:


Get-CimClass -Namespace 'root\wmi'

Using Command Prompt powercfg Command

powercfg command can be used to generate report containing information about battery including cycle count.

Below command consists of two steps in order to get CycleCount information. The first is generating battery report to xml and the second is querying CycleCount property.


powercfg /batteryreport /output "batteryreport.xml" /xml

[xml]$report = Get-Content C:\Scripts\batteryreport.xml

$report.BatteryReport.Batteries | ForEach-Object {
    $_.Battery.CycleCount
}

The report can also be generated in HTML which is the default format using this command:


powercfg /batteryreport

And the HTML report will look like below:

powercfg battery report

Conclusion

To get cycle information in Windows, you can use PowerShell cmdlets as well command from windows command prompt.