Skip to content

Retrieves basic battery information (a Windows PowerShell script).

License

Notifications You must be signed in to change notification settings

auberginehill/get-battery-info

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Get-BatteryInfo.ps1

OS: Windows
Type: A Windows PowerShell script
Language: Windows PowerShell
Description: Get-BatteryInfo uses Windows Management Instrumentation (WMI) to retrieve basic battery and computer information and displays the results in console. On Windows 8+ machines Get-BatteryInfo also launches the inbuilt PowerCfg /batteryreport command to generate a detailed Battery Report HTML-file.
Homepage: https://github.com/auberginehill/get-battery-info
Short URL: http://tinyurl.com/jnnuvq3
Version: 1.1
Sources:
Emojis: Emoji Table
Richard: How to find the Windows version from the PowerShell command line?
JaredPar and Matthew Pirocchi: What's the best way to determine the location of the current PowerShell script?
ZDNet: Windows 10 tip: Check the performance of your laptop battery
Downloads: For instance Get-BatteryInfo.ps1. Or everything as a .zip-file.

Screenshot

        screenshot

Outputs

➡️
  • General computer information, such as Computer, Manufacturer, Computer Model, System Type, Domain Role, Chassis, PC Type, Processes, Average CPU Load and whether the machine is a laptop or not (based on the chassis information) is displayed along with battery related information, such as Total Number of installed Batteries, Battery Class, Battery Name, Battery Type, Estimated Charge Remaining, Estimated Run Time, Battery Voltage, Battery Availability, Battery Status, Battery Chemistry, Power Management Capabilities, Status, Battery Level and Remaining Battery Time in console. On Windows 8+ machines also a detailed Battery Report (battery-report.html and an adjacent XML-file) will be created at $path.

Notes

⚠️
  • Please note that on Windows 8+ machines the battery report files will be created in a directory, which is specified with the $path variable (at line 6).

  • The $env:temp variable points to the current temp folder. The default value of the $env:temp variable is C:\Users\<username>\AppData\Local\Temp (i.e. each user account has their own separate temp folder at path %USERPROFILE%\AppData\Local\Temp). To see the current temp path, for instance a command

    [System.IO.Path]::GetTempPath()

    may be used at the PowerShell prompt window [PS>]. To change the temp folder for instance to C:\Temp, please, for example, follow the instructions at Temporary Files Folder - Change Location in Windows, which in essence are something along the lines:
    1. Right click on Computer and click on Properties (or select Start → Control Panel → System). In the resulting window with the basic information about the computer...
    2. Click on Advanced system settings on the left panel and select Advanced tab on the resulting pop-up window.
    3. Click on the button near the bottom labeled Environment Variables.
    4. In the topmost section labeled User variables both TMP and TEMP may be seen. Each different login account is assigned its own temporary locations. These values can be changed by double clicking a value or by highlighting a value and selecting Edit. The specified path will be used by Windows and many other programs for temporary files. It's advisable to set the same value (a directory path) for both TMP and TEMP.
    5. Any running programs need to be restarted for the new values to take effect. In fact, probably also Windows itself needs to be restarted for it to begin using the new values for its own temporary files.

Examples

📖 To open this code in Windows PowerShell, for instance:

  1. ./Get-BatteryInfo
    Run the script. Please notice to insert ./ or .\ before the script name.
  2. help ./Get-BatteryInfo -Full
    Display the help file.
  3. Set-ExecutionPolicy remotesigned
    This command is altering the Windows PowerShell rights to enable script execution. Windows PowerShell has to be run with elevated rights (run as an administrator) to actually be able to change the script execution properties. The default value is "Set-ExecutionPolicy restricted".

    Parameters:

      Restricted Does not load configuration files or run scripts. Restricted is the default execution policy.
      AllSigned Requires that all scripts and configuration files be signed by a trusted publisher, including scripts that you write on the local computer.
      RemoteSigned Requires that all scripts and configuration files downloaded from the Internet be signed by a trusted publisher.
      Unrestricted Loads all configuration files and runs all scripts. If you run an unsigned script that was downloaded from the Internet, you are prompted for permission before it runs.
      Bypass Nothing is blocked and there are no warnings or prompts.
      Undefined Removes the currently assigned execution policy from the current scope. This parameter will not remove an execution policy that is set in a Group Policy scope.

    For more information, please type "help Set-ExecutionPolicy -Full" or visit Set-ExecutionPolicy.

  4. New-Item -ItemType File -Path C:\Temp\Get-BatteryInfo.ps1
    Creates an empty ps1-file to the C:\Temp directory. The New-Item cmdlet has an inherent -NoClobber mode built into it, so that the procedure will halt, if overwriting (replacing the contents) of an existing file is about to happen. Overwriting a file with the New-Item cmdlet requires using the Force.
    For more information, please type "help New-Item -Full".

Contributing

Find a bug? Have a feature request? Here is how you can contribute to this project:

contributing Bugs: Submit bugs and help us verify fixes.
Feature Requests: Feature request can be submitted by creating an Issue.
Edit Source Files: Submit pull requests for bug fixes and features and discuss existing proposals.

www

www Script Homepage
Win32_Battery class
Win32_SystemEnclosure class
Win32_ComputerSystem class
Win32_OperatingSystem class
OSVERSIONINFOEX structure
How to find the Windows version from the PowerShell command line?
What's the best way to determine the location of the current PowerShell script?
Windows 10 tip: Check the performance of your laptop battery
ASCII Art: http://www.figlet.org/ and ASCII Art Text Generator

Related scripts

www Firefox Customization Files
Get-AsciiTable
Get-ComputerInfo
Get-DirectorySize
Get-InstalledPrograms
Get-InstalledWindowsUpdates
Get-RAMInfo
Get-TimeDifference
Get-TimeZoneTable
Get-UnusedDriveLetters
Emoji Table
Java-Update
Rock-Paper-Scissors
Toss-a-Coin
Update-AdobeFlashPlayer