Check CPU Battery Status

Code Properties

  • Language: PowerShell
  • Cmdlets: Get-CimInstance

Overview

PowerShell script that retrieves battery status information using WMI/CIM, including current charge percentage, charging status, and estimated time to full charge.

Code

$b = Get-CimInstance Win32_Battery
 
$batteryStatus = (@{
    1 = 'Discharging'
    2 = 'Connected to AC'
    3 = 'Fully charged'
    4 = 'Low'
    5 = 'Critical'
    6 = 'Charging'
    7 = 'Charging/High'
    8 = 'Charging/Low'
    9 = 'Charging/Critical'
   10 = 'Undefined'
   11 = 'Partially Charged'
})[$b.batteryStatus -as [int]]
 
"$($b.caption) $($b.name): $($b.status)"
"  Status:              $batteryStatus ($($b.batteryStatus))"
"  Charged:             $($b.estimatedChargeRemaining) %"
 
if ($b.timeToFullCharge) {
    "  Time to full charge: $($b.timeToFullCharge) Minutes"
}

Usage

Run the script directly in a PowerShell session to get current battery information:

.\Get-BatteryStatus.ps1

Appendix

Note created on 2024-09-18 and last modified on 2024-12-31.

See Also


(c) No Clocks, LLC | 2024