≡ Menu

Hey PowerShell, What is my laptop battery status?

Yesterday I wrote about different ways to check how much charge is left in the laptop battery. After that I explored win32_battery WMI class further and got some more useful information.

How do you know your battery current status, like is it charging properly?, is it running low, it is full with charge, it is partially charged, is the charge is too low?. It is easy to answer this kind of questions if you can interpret batterystatus attribute of Win32_Battery WMI class. Let us see the possible values this attribute can hold and their meaning.

Value Meaning

1
The battery is discharging.

2
The system has access to AC so no battery is being discharged. However, the battery is not necessarily charging.

3
Fully Charged

4
Low

5
Critical

6
Charging

7
Charging and High

8
Charging and Low

9
Charging and Critical

10
Undefined

11
Partially Charged

*Above table is copied from MSDN site.

Now let us write a script to check the battery current status.

Function Check-BatteryState {
param($Laptop=$env:computername)
$Bstatus = (Get-WmiObject -Class Win32_Battery -ea 0).BatteryStatus
if($Bstatus) {
    switch ($Bstatus)
    {
    1 { "Battery is discharging" }
    2 { "The system has access to AC so no battery is being discharged. However, the battery is not necessarily charging." }
    3 { "Fully Charged" }
    4 { "Low" }
    5 { "Critical" }
    6 { "Charging" }
    7 { "Charging and High" }
    8 { "Charging and Low" }
    9 { "Charging and Critical " }
    10 { "Unknown State" }
    11 { "Partially Charged" }            

    }
}
}

This powershell function helps you to identify current status of laptop battery. Hope this helps..


{ 2 comments… add one }
  • Charles Fraser December 27, 2017, 4:00 am

    I copied and pasted this into a new powershell script and ran it, nothing happened. I didn’t get an error or any results. Is there something I’m supposed to add to this? I’m super new at this and don’t really know anything but am trying to get into powershell to help automate things at work. Thanks!

    • Wintel Rocks December 29, 2017, 6:40 pm

      Hi,

      its a PowerShell function. So you need to call the function “Check-BatteryState” after pasting the code into powershell window.

Leave a Comment