Description
I have prepared this Powershell script to use it in SCOM but of course it can be used also as a standalone script or it can be scheduled in Task Manager too.
The logic behind it was to log an event into the clients application event log and collect the events later with an “Event Collection Rule” in SCOM and archive it on the DataWarehouse. By retrieving the events with T-SQL query we would then have a list of healthy and unhealthy PC’s.
This script is also available on TechNet Script Gallery for download.
https://gallery.technet.microsoft.com/scriptcenter/Notebook-Battery-Health-43402e40
Powershell Script
# BatteryHealthCheck.ps1
# Version 1.0
# Date: 8/28/2018
# Author: Cengiz KUSKAYA (www.Kuskaya.Info)
# Description: The purpose of this Powershell Battery Health Check Script was to use it with
# SCOM . Basically checking the Battery Health, logging an Event about the Health Status and
# collecting the Events later with an Event Collection Rule to get a list of PC's with
# healthy and unhealty status.
# Check EventLog for Source "BatteryHealthCheck". $ProviderList = (Get-WinEvent -ListLog Application).ProviderNames if ($ProviderList -notcontains "BatteryHealthCheck") # If "BatteryHealthCheck" Event Source not available, create it. {New-EventLog -LogName "Application" -Source "BatteryHealthCheck"} # Minimum Acceptable Health Percentage. $MinHealth = "99" # Checking Battery Spesification. $BatteryDesignSpec = (Get-WmiObject -Class "BatteryStaticData" -Namespace "ROOT\WMI").DesignedCapacity $BatteryFullCharge = (Get-WmiObject -Class "BatteryFullChargedCapacity" -Namespace "ROOT\WMI").FullChargedCapacity # Check if Battery Replacement is required. [int]$CurrentHealth = ($BatteryFullCharge/$BatteryDesignSpec) * 100 if ($CurrentHealth -le $MinHealth) {write-eventlog -logname Application -source BatteryHealthCheck -eventID 9999 -entrytype Error -message "Battery needs to be replaced $CurrentHealth !" -EA SilentlyContinue} if ($CurrentHealth -gt $MinHealth) {write-eventlog -logname Application -source BatteryHealthCheck -eventID 8888 -entrytype Information -message "Battery is healthy $CurrentHealth !" -EA SilentlyContinue} if ($CurrentHealth -eq $MinHealth) {write-eventlog -logname Application -source BatteryHealthCheck -eventID 8888 -entrytype Information -message "Battery is healthy $CurrentHealth !" -EA SilentlyContinue} # END
Good luck !