Last active
January 16, 2024 03:39
-
-
Save EvansWinner/50ed838229285bc4a5053c085329a3a2 to your computer and use it in GitHub Desktop.
Quick get battery status on Windows Powershell command line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I am used to typing "acpi" at the command line in Linux to see | |
# what my battery status is. I'm sure acpi does all kinds of other | |
# useful stuff, but that's what I am used to having. Here | |
# is something to do the same in Windows Powershell calling | |
# out to the wmic program. I have it it my $profile file. | |
# Also uses findstr and a list of output code meaning I found on | |
# Stackexchange or somewhere.... (Sorry, don't remember where.) | |
function acpi{ | |
wmic path Win32_Battery Get EstimatedChargeRemaining | |
$code=wmic path Win32_Battery Get BatteryStatus | findstr /v "Status" | |
$code=$code.replace(" ","").replace("`n","") | |
$status=@{ | |
'1'="Discharging (Other)"; | |
'4'="Discharging (Low)"; | |
'5'="Discharging (Critical)"; | |
'2'="Charging (Unknown)"; | |
'6'="Charging"; | |
'7'="Charging (High)"; | |
'8'="Charging (Low)"; | |
'9'="Charging (Critical)"; | |
'11'="Partially Charged"; | |
'3'="Fully Charged"; | |
'10'="Not Present (Undefined)"; | |
} | |
echo $status[$code] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
mine only ever gets 1 or 2 so I guess the api is broken
wmic path Win32_Battery Get BatteryStatus
. I am trying to find if the powercfg is currently running on AC or DC so I can fetch the appropriate power mode overlay registry settingHKLM\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes
with value ofActiveOverlayAcPowerScheme
orActiveOverlayDcPowerScheme