Posted on 11-01-2023 11:26 AM
Battery capacity under Hardware section shows 1% in Jamf Pro 11 (not sure if this issue existed prior).
When I look in System Information, it's at 94%.
Posted on 11-01-2023 11:48 AM
Information in Jamf Pro is only as current as the last inventory of the computer, which is once per week by default. It’s not live.
Posted on 11-01-2023 12:15 PM
Sure. I should've mentioned that I ran recon manually and the information stayed the same.
Posted on 11-08-2023 07:27 AM
Funnily enough I was asked to gather battery health information last week, and found the same thing where the battery capacity often reported wrong (only on Apple Silicon from what I can see). I whipped up the following extension attribute script to gather what we need. There's a list of Intel MacBooks we care about, with their factory battery capacity, whereas Apple Silicon reports this information differently, so no list needed for them:
#!/bin/bash
#The list of Intel models we know factory battery capacity for
models="MacBookPro11,1:6330|MacBookPro11,2:8440|MacBookPro11,3:8440|MacBookPro11,4:8755|MacBookPro11,5:8755|MacBookPro12,1:6559|MacBookPro13,1:4781|MacBookPro13,2:4314|MacBookPro13,3:6667|MacBookPro14,1:4781|MacBookPro14,2:4314|MacBookPro14,3:6667|MacBookPro15,1:7336|MacBookPro15,2:5086|MacBookPro15,3:7336|MacBookPro15,4:5103|MacBookPro16,1:8790|MacBookPro16,2:5086|MacBookPro16,3:5103|MacBookPro16,4:8790|MacBookAir6,1:5100|MacBookAir6,2:7150|MacBookAir5,1:5100|MacBookAir7,2:7150|MacBookAir8,1:4379|MacBookAir8,2:4379|MacBookAir9,1:4379|MacBookAir6,1:5100"
#The result of the script
scriptResult=""
#Get the hardware information
intelCPU=$(sysctl -n machdep.cpu.brand_string | grep -ci Intel)
modelID=$(system_profiler SPHardwareDataType | grep "^ *Model Identifier" | sed "s|^ *Model Identifier: *||")
#Check for an Intel CPU
if [[ ! $intelCPU -eq 0 ]]
then
#Check for a matching Intel laptop model
modelMatch=$(echo "$models" | grep "$modelID" | sed "s|^.*\($modelID:[0-9]*\).*$|\1|")
#If there was a match, then calculate the battery health based on the new capacity vs. the reported current capacity
if [[ ${#modelMatch} -gt 0 ]]
then
#Get the power data
powerData=$(system_profiler SPPowerDataType)
#Get the factory capacity
newCapacity=$(echo "$modelMatch" | cut -d ':' -f2)
#Get the reported current capacity
currentCapacity=$(echo "$powerData" | grep "^ *Full Charge Capacity" | sed "s|^ *Full Charge Capacity (mAh): *||")
#Get the reported current cycle count
currentCycles=$(echo "$powerData" | grep "^ *Cycle Count" | sed "s|^ *Cycle Count: *||")
#Get the reported battery condition
condition=$(echo "$powerData" | grep "^ *Condition" | sed "s|^ *Condition: *||")
#Figure out the battery health as a percentage
batteryHealth=$(echo "scale=2; $currentCapacity / $newCapacity * 100" | bc | cut -d '.' -f1)
batteryHealth="$batteryHealth""%"
#The cycle information
cycles="$currentCycles""/1000"
else
#No match, so this model we don't care about since it's either too old, or a desktop
scriptResult="N/A"
fi
else
#This is an Apple Silicon CPU, so get the information differently
#Get the power data
powerData=$(system_profiler SPPowerDataType)
#Get the battery health as a percentage
batteryHealth=$(echo "$powerData" | grep "^ *Maximum Capacity" | sed "s|^ *Maximum Capacity: *||")
#If the battery health information exists, then process it, otherwise this is a desktop so report "N/A"
if [[ ! ${#batteryHealth} -eq 0 ]]
then
#Get the reported current cycle count
currentCycles=$(echo "$powerData" | grep "^ *Cycle Count" | sed "s|^ *Cycle Count: *||")
#Get the reported battery condition
condition=$(echo "$powerData" | grep "^ *Condition" | sed "s|^ *Condition: *||")
#The cycle information
cycles="$currentCycles""/1000"
else
scriptResult="N/A"
fi
fi
#If the result earlier was not "N/A" then put together the result string to report to Jamf
if [[ ${#scriptResult} -eq 0 ]]
then
scriptResult="Battery Health: $batteryHealth Cycles: $cycles Condition: $condition"
fi
echo "<result>$scriptResult</result>"
Posted on 10-10-2024 11:47 PM
Cool script.
I think it can be accomplished in one line though. This EA works for Big Sur through Sequoia; it returns an integer if there is a battery, and a null value if it's a desktop.
https://happymacadmin.wordpress.com/2024/10/10/read-a-macs-battery-health-with-the-pmset-utility/