Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # Filename: batstats.ps1
- # Version: 1.0.0
- # Author: Jeoi Reqi
- # This script retrieves battery information using the wmi module.
- # It's designed for Windows, requiring Python 3.x and wmi.
- # The script presents battery details like status and charge level clearly.
- # Users can quickly gauge battery health and make informed decisions about power usage.
- #
- # Before running the script, navigate to the directory where the script is located using the PowerShell terminal.
- # Then, run the script using the following command: .\battery.ps1
- # Get battery information
- $b = Get-CimInstance Win32_Battery
- # Define battery status descriptions
- $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'
- }[[int]$b.BatteryStatus]
- # Print battery information header
- Write-Output "--------------------------------------------------"
- Write-Output "`t`t:: BATTERY STATS ::"
- Write-Output "--------------------------------------------------"
- # Print battery information
- Write-Output ""
- Write-Output "$($b.Caption): [$($b.Name)] Status: $($b.Status)"
- Write-Output "Battery Status: $batteryStatus ($($b.BatteryStatus))"
- Write-Output "Charge Remaining: $($b.EstimatedChargeRemaining)%"
- Write-Output ""
- Write-Output "--------------------------------------------------"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement