Access Power and Battery Status with PowerShell


Access Power and Battery Status with PowerShell. Unfortunately this only applies to Windows
Tested on Windows 10
Detect power status with PowerShell

BatteryChargeStatus, BatteryFullLifetime, BatteryLifePercent, and BatteryLifeRemaining


Windows Logo

Code

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

Plugged In

PowerLineStatus      : Online
BatteryChargeStatus  : High
BatteryFullLifetime  : -1
BatteryLifePercent   : 1
BatteryLifeRemaining : -1

Unplugged

PowerLineStatus      : Offline
BatteryChargeStatus  : High
BatteryFullLifetime  : -1
BatteryLifePercent   : 0.95
BatteryLifeRemaining : -1

PowerLineStatus      : Offline
BatteryChargeStatus  : High
BatteryFullLifetime  : -1
BatteryLifePercent   : 0.82
BatteryLifeRemaining : 9369

PowerLineStatus      : Offline
BatteryChargeStatus  : 0
BatteryFullLifetime  : -1
BatteryLifePercent   : 0.56
BatteryLifeRemaining : 5282
  • https://github.com/powershell/powershell