Advertisement
Python253

batstats.ps1

May 6th, 2024
934
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Filename: batstats.ps1
  4. # Version: 1.0.0
  5. # Author: Jeoi Reqi
  6.  
  7. # This script retrieves battery information using the wmi module.
  8. # It's designed for Windows, requiring Python 3.x and wmi.
  9. # The script presents battery details like status and charge level clearly.
  10. # Users can quickly gauge battery health and make informed decisions about power usage.
  11. #
  12. # Before running the script, navigate to the directory where the script is located using the PowerShell terminal.
  13. # Then, run the script using the following command: .\battery.ps1
  14.  
  15. # Get battery information
  16. $b = Get-CimInstance Win32_Battery
  17.  
  18. # Define battery status descriptions
  19. $batteryStatus = @{
  20.     1 = 'Discharging'
  21.     2 = 'Connected to AC'
  22.     3 = 'Fully charged'
  23.     4 = 'Low'
  24.     5 = 'Critical'
  25.     6 = 'Charging'
  26.     7 = 'Charging/High'
  27.     8 = 'Charging/Low'
  28.     9 = 'Charging/Critical'
  29.     10 = 'Undefined'
  30.     11 = 'Partially Charged'
  31. }[[int]$b.BatteryStatus]
  32.  
  33. # Print battery information header
  34. Write-Output "--------------------------------------------------"
  35. Write-Output "`t`t:: BATTERY STATS ::"
  36. Write-Output "--------------------------------------------------"
  37.  
  38. # Print battery information
  39. Write-Output ""
  40. Write-Output "$($b.Caption): [$($b.Name)]    Status: $($b.Status)"
  41. Write-Output "Battery Status:                $batteryStatus ($($b.BatteryStatus))"
  42. Write-Output "Charge Remaining:              $($b.EstimatedChargeRemaining)%"
  43. Write-Output ""
  44. Write-Output "--------------------------------------------------"
  45.  
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement