Quantcast
Channel: Geeks Hangout - Code
Viewing all articles
Browse latest Browse all 10

PowerShell script to show the state of your laptop battery

$
0
0

Windows holds so much great information in the WMI including information on the battery.

The below is a little PowerShell function that will show you what state your laptop battery is in full, charging etc.

Function Check-BatteryState {
param($Laptop=$env:computername)
$Bstatus=(Get-WmiObject-Class Win32_Battery -ea 0).BatteryStatus
if($Bstatus){
    switch($Bstatus)
    {
    1{"Battery is discharging"}
    2{"The system has access to AC so no battery is being discharged. However, the battery is not necessarily charging."}
    3{"Fully Charged"}
    4{"Low"}
    5{"Critical"}
    6{"Charging"}
    7{"Charging and High"}
    8{"Charging and Low"}
    9{"Charging and Critical "}
    10{"Unknown State"}
    11{"Partially Charged"}           

    }
}
}

And on the same lines are the two below one liners.

Check the percentage of charging left in the battery;

(Get-WmiObject-Class Win32_Battery).estimatedchargeremaining

An estimate of how many minutes charge are remaining;

(Get-WmiObject-Class Win32_Battery).EstimatedRunTime

There is a whole load of other good battery information in WMI such as the availability, chemistryand errors \ condition take a look at  W32_Battery Class for more info.

You could very easiler create a script to query the condition of you laptops batteries to find ones with a poor condition battery and laptops with have a second battery etc.


Viewing all articles
Browse latest Browse all 10

Trending Articles