Detecting Power Status

by Feb 25, 2022

While it is hard to directly access the Windows Power Management API, there are other API calls that can do this for you. The following one-liner returns the current power status of your machine. If you are using a notebook and have no AC power, it can tell you the remaining battery power:

Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.SystemInformation]::PowerStatus

The result looks similar to this:

 
PowerLineStatus      : Offline
BatteryChargeStatus  : 0
BatteryFullLifetime  : -1
BatteryLifePercent   : 0,45
BatteryLifeRemaining : 13498 
 


Twitter This Tip! ReTweet this Tip!