Gathering Battery Information via PowerShell & WMI

TLDR: GitHub Script: garytown/BatteryInfo.ps1

If you have an HP Device, there is a nifty utility called HP Power Manager, in which it tells you the health and status of your battery.

Related Posts:

This is pretty useful, but sometimes you need to access this information via PowerShell or WMI for scripting or Inventory. I’m going to cover several things in the post on where to pull that information from.

To install HP Power Manager via PowerShell if you have HPCMSL:

$SoftPaqInfo = Get-SoftpaqList -Category Software | Where-Object {$_.Name -match "Power Manager"}
Get-Softpaq -Number $ -SaveAs "C:\swsetup\$($" -Action silentinstall

I wrote up a script (listed above) which will pull this information from WMI. GitHub Script: garytown/BatteryInfo.ps1
On AC Connection:

On Battery:

When on battery, it will also display the Estimated Run Time.

I’m pulling the battery information from several WMI Classes and two name spaces.
First, we’ll look at the one everyone is typically used to: Win32_Battery

From this Class, I’m using EstimatedChargeRemaining, which is a % & EstimatedRunTime, which is in Minutes.

I then head over to Root\WMI and look at the Battery Classes there:

Get-CimInstance -Namespace ROOT\WMI -ClassName "BatteryCycleCount"
Get-CimInstance -Namespace ROOT\WMI -ClassName "BatteryFullChargedCapacity"
Get-CimInstance -Namespace ROOT\WMI -ClassName "BatteryRuntime"
Get-WmiObject -Namespace ROOT\WMI -ClassName "BatteryStaticData"
#Note use Get-WmiObject instead of Get-CimInstance
Get-CimInstance -Namespace ROOT\WMI -ClassName "BatteryStatus"

So that is how I’m pulling all of the information in to my script:

  • Win32_Battery
    • EstimatedChargeRemaining (%)
    • EstimatedRunTime (Minutes)
  • BatteryCycleCount
    • CycleCount
  • BatteryFullChargedCapacity
    • FullChargedCapacity (milliwatt-hours)
  • BatteryRuntime
    • EstimatedRuntime (Seconds)
  • BatteryStaticData
    • DesignedCapacity (milliwatt-hours)
    • SerialNumber
    • ManufactureName
  • BatteryStatus
    • DischargeRate (Milliwatt)
    • Discharging (True/False)
    • Charging (True/False)
    • PowerOnline (True/False)
    • Voltage (millivolts)
    • RemainingCapacity (milliwatt-hours)

Temperature, this was the tricky one, as I couldn’t get the Class to work, always came back blank, so I decided to pull the info from MsAcpi_ThermalZoneTemperature

Get-CimInstance -Namespace root/wmi -ClassName MsAcpi_ThermalZoneTemperature | Where-Object {$_.InstanceName -match "BATZ"}

From there, it’s a conversation to C & F, which I found someone had done on stackoverflow, so I pulled that code and modified it for this script.

So, now you have this information, what ya gonna do with it? Well, you could use the FullChargeCapacity and devide that by the DesignedCapacity and see how good the battery is performing… then a little more math, and you can get the degraded %, then setup alerts to re-order batteries when they reach a threshold your business sets.

Write-Output "Battery Degraded :   $([math]::Round(100 - (($FullChargedCapacity / $DesignedCapacity)*100))) %"

So that’s not too bad… let me test a couple more devices…

And now I’ll confirm that last one with the HP tool:

That confirms my script is working. The HP Tool says that the battery capacity is 83% of new, which means my 17% degraded in the script output is correct.

I hope you found this useful or at least interesting.


2 thoughts on “Gathering Battery Information via PowerShell & WMI”

  1. Right after you said
    “I then head over to Root\WMI and look at the Battery Classes there:”
    How did you get to that UI to see that list of battery classes where it shows if its True/False and the description. Thanks


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.