Friday, May 10, 2024
HomePowershellMonitoring with PowerShell: Monitoring battery well being

Monitoring with PowerShell: Monitoring battery well being


This one was requested by a number of customers for some time, I added this to some script libraries however by no means really launched it on the weblog so I figured it’s a great way to get again into running a blog.

The monitor is fairly easy; first we run a command to test every battery within the system, we add this to an object. This object incorporates the reported details about the battery, How a lot cost it ought to have, in keeping with the producer, how a lot cost it’s really holding, and the place the battery got here from and a few figuring out properties.

This script has been examined on a variety of gadgets, however after all, some gadgets would possibly fail at battery detection, or some simply don’t report any quantity. If that’s the case, the script simply writes this to the host with out exiting.

The Script

Load this script up in your RMM for ease of execution, and have enjoyable. 🙂

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$AlertPercent = "70"

& powercfg /batteryreport /XML /OUTPUT "batteryreport.xml"
Begin-Sleep 1
[xml]$Report = Get-Content material "batteryreport.xml"

$BatteryStatus = $Report.BatteryReport.Batteries |
ForEach-Object {
[PSCustomObject]@{
DesignCapacity = $_.Battery.DesignCapacity
FullChargeCapacity = $_.Battery.FullChargeCapacity
CycleCount = $_.Battery.CycleCount
Id = $_.Battery.id
}
}

if (!$BatteryStatus) {
Write-Host "This system doesn't have batteries, or we couldn't discover the standing of the batteries."
}

foreach ($Battery in $BatteryStatus) {
    if ([int64]$Battery.FullChargeCapacity * 100 / [int64]$Battery.DesignCapacity -lt $AlertPercent) {
        Write-host "The battery well being is lower than count on. The battery was designed for $($battery.DesignCapacity) however the most cost is $($Battery.FullChargeCapacity). The battery data is $($Battery.id)"

    }

}

And as all the time, Blissful PowerShelling 🙂

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments