How to Check Your Laptop's Battery Health with a Simple PowerShell Script ✨

Check your laptop's battery health with a simple PowerShell script. Learn how to monitor your battery's cycle count, and overall health. Read now!
Laptop Battery Health Powershell Script

Are you tired of wondering how much battery life your laptop has left? Do you want to know if an app or system process is draining your battery faster than usual? Well, wonder no more! With just a few lines of code, you can create a simple PowerShell script that displays all the juicy details about your laptop's battery.

In this blog post, we'll show you how to write a quick PowerShell script that retrieves information about your laptop's battery, including its total number of charge cycles, battery design capacity, battery current capacity, battery health or remaining total percentage, discharge rate, and charging rate. We'll also provide step-by-step instructions on how to run the script and interpret the results.

The Script

First things first, let's take a look at the script itself. Here's what you need to copy and paste into a file named "battery_info.ps1":

# Retrieves the number of charge cycles the battery has gone through
$Cycles = (Get-WmiObject -Class BatteryCycleCount -Namespace ROOT\WMI).CycleCount

# Outputs the number of charge cycles to the console
Write-Host "Charge cycles: $Cycles"

# Retrieves the designed capacity of the battery in milliampere-hours (mAh)
$DesignCapacity = (Get-WmiObject -Class BatteryStaticData -Namespace ROOT\WMI).DesignedCapacity

# Outputs the designed capacity of the battery to the console
Write-Host "Design capacity: $DesignCapacity mAh"

# Retrieves the full charged capacity of the battery in mAh
$FullCharge = (Get-WmiObject -Class BatteryFullChargedCapacity -Namespace ROOT\WMI).FullChargedCapacity

# Outputs the full charged capacity of the battery to the console
Write-Host "Full charge: $FullCharge mAh"

# Calculates the battery health as a percentage
$BatteryHealth = ($FullCharge / $DesignCapacity) * 100

# Rounds the battery health to two decimal places
$BatteryHealth = [math]::Round($BatteryHealth, 2)

# Outputs the battery health as a percentage to the console
Write-Host "Battery health: $BatteryHealth%"

# Retrieves the discharge rate of the battery in milliamps (mA)
$Discharge = (Get-WmiObject -Class BatteryStatus -Namespace ROOT\WMI).DischargeRate

# Outputs the discharge rate of the battery to the console
Write-Host "Discharge rate: $Discharge mA"

# Retrieves the charging rate of the battery in milliamps (mA)
$Charging = (Get-WmiObject -Class BatteryStatus -Namespace ROOT\WMI).ChargeRate

# Outputs the charging rate of the battery to the console
Write-Host "Charging rate: $Charging mA"

Now that you have the script, let's talk about what each line does.

Line 1 This line retrieves the number of charge cycles the battery has gone through. It uses the Get-WmiObject cmdlet to query the Windows Management Instrumentation (WMI) service for the BatteryCycleCount class, which is part of the ROOT\WMI namespace. The .CycleCount property is used to retrieve the number of charge cycles.

Line 2 This line simply outputs the number of charge cycles to the console.

Line 3 This line retrieves the designed capacity of the battery in milliampere-hours (mAh). It uses the Get-WmiObject cmdlet to query the BatteryStaticData class, which is also part of the ROOT\WMI namespace. The .DesignedCapacity property is used to retrieve the designed capacity.

Line 4 This line outputs the designed capacity of the battery to the console.

Line 5 This line retrieves the full charged capacity of the battery in mAh. It uses the Get-WmiObject cmdlet to query the BatteryFullChargedCapacity class, which is part of the ROOT\WMI namespace. The .FullChargedCapacity property is used to retrieve the full charged capacity.

Line 6 This line outputs the full charged capacity of the battery to the console.

Line 7 This line calculates the battery health as a percentage. It divides the full charged capacity by the designed capacity and multiplies the result by 100.

Line 8 This line rounds the battery health to two decimal places using the [math]::Round() function.

Line 9 This line outputs the battery health as a percentage to the console.

Line 10 This line retrieves the discharge rate of the battery in milliamps (mA). It uses the Get-WmiObject cmdlet to query the BatteryStatus class, which is part of the ROOT\WMI namespace. The .DischargeRate property is used to retrieve the discharge rate of the battery.

Line 11 This line outputs the discharge rate of the battery to the console.

Line 12 This line retrieves the charging rate of the battery in mA. It uses the same method as before to query the BatteryStatus class and retrieve the .ChargeRate property.

Line 13 This line outputs the charging rate of the battery to the console.

Running the Script

To run the script, follow these steps:

1. Copy and paste the script into a text editor such as Notepad. Save the file with a .ps1 extension (e.g., battery_info.ps1).

2. Open a PowerShell window or command prompt. You can do this by searching for "PowerShell" in the Start menu or by typing cmd in the Run dialog box (Windows key + R).

3. Navigate to the directory where you saved the script file. Type cd path/to/folder followed by Enter, replacing path/to/folder with the actual path to the folder containing the script file.

4. Type powershell -File battery_info.ps1 followed by Enter. This will execute the script and display the battery information in the PowerShell console.

Note: Do not forgot to replace battery_info.ps1 with the name of the file you saved.

Interpreting the Results

Once you've executed the script, you'll see six different values displayed in the PowerShell console. Let's go over what each value means:

Screenshot

Charge Cycles: This tells you how many times the battery has been charged and discharged. A higher number indicates that the battery is nearing the end of its lifespan. I have disabled tracking my charge cycles on windows 11, so mine is showing it as 0, this might be something else in your case :b

Design Capacity: This shows the maximum capacity of the battery when it was new. It gives you an idea of how much energy the battery could hold originally.

Full Charge: This shows the current capacity of the battery, which may be lower than the design capacity due to wear and tear over time.

Battery Health (%): This shows the overall health of the battery as a percentage. A lower percentage indicates that the battery is nearing the end of its useful life.

Discharge Rate: This shows the rate at which the battery is currently discharging power.

Charging Rate: This shows the rate at which the battery is currently charging power.

Tips and Tricks

Here are some tips and tricks to help you get the most out of your battery:

  • Keep your laptop away from high temperatures, as heat can damage the battery and cause it to degrade faster.
  • Avoid overcharging your battery, as this can reduce its lifespan. Try to keep the battery level between 20% and 80%.
  • Use a high-quality charger and avoid cheap knockoffs, as they may not provide the correct voltage which harms battery.
  • Turn off unnecessary features when not in use, such as WiFi, Bluetooth, and keyboard light, to conserve battery power.
  • Adjust your screen brightness to a comfortable level, as a brighter screen consumes more power.
  • Consider upgrading to a newer, more efficient battery if yours is several years old and showing signs of degradation.

Conclusion

In conclusion, monitoring your laptop's battery health is essential to ensure that you get the most out of your device. By following the steps outlined in this guide, you can easily check your battery's health and make informed decisions about its maintenance and replacement. Remember to keep your battery cool, avoid overcharging, and use a high-quality charger to prolong its lifespan. 

Happy computing!

    I post, u read. Read more.

    Post a Comment

    Don't spam links or promote stuff in the comments. It's annoying and lowers the conversation quality. Contribute respectfully and helpfully instead.