PoshTip #24 – How to know the state of your laptop battery?

PoshTip #24 – How to know the state of your laptop battery?

Many informations are included in WMI. Here, we will use the Win32_Battery class to get the state of the battery. Just use the Get-WMIObject cmdlet:

Get-WmiObject -Class Win32_Battery

And now, you just have to add the BatteryStatus property:

$BatteryState = (Get-WmiObject -Class Win32_Battery).BatteryStatus

the output is a number include between 1 and 11. You can find explanation on this page: https://msdn.microsoft.com/en-us/library/aa394074(v=vs.85).aspx

PS> $BatteryState
2

In my example, the output is 2 which mean : “The system has access to AC so no battery is being discharged. However, the battery is not necessarily charging.”

Thanks for reading! You can follow me on Twitter @PrigentNico

About Nicolas 282 Articles
I work as an IT Production Manager, based in Paris (France) with a primary focus on Microsoft technologies. I have 10 years experience in administering Windows Servers. . I am a Microsoft MVP for Cloud & Datacenter Management. I also received the PowerShell Hero 2016 award by PowerShell.0rg. And finally, I am "MCSE: Cloud Platform and Infrastructure", "MCSA: Windows Servers", "Administering & Deploying SCCM", and CheckPoint CCSA certified.