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