Skip to main content
Solved

Extension attribute not showing

  • February 22, 2023
  • 5 replies
  • 18 views

Forum|alt.badge.img+2

I've created this script in an Extension attribute but it's not showing.

#!/bin/bash
echo "<result>$(system_profiler SPPowerDataType | grep "Maximum Capacity:" | sed 's/.*Maximum Capacity: //')</result>"

exit 0

Could someone see what's the issue?

Best answer by cdev

Seems like the sed statement isn't working as intended...I'd suggest the following:

system_profiler SPPowerDataType | grep "Maximum Capacity:" | cut -d ":" -f2

5 replies

mm2270
Forum|alt.badge.img+24
  • Legendary Contributor
  • 7886 replies
  • February 22, 2023

Has an inventory collection happened on at least one Mac yet? Because new EAs don't show any results until a Mac submits inventory and runs the script.

Edit: The other thing is, just running this command by itself - system_profiler SPPowerDataType | grep "Maximum Capacity:" | sed 's/.*Maximum Capacity: //' - doesn't yield any results for me. Are you sure this should be getting information you're looking for? You might need to double check your code.


cdev
Forum|alt.badge.img+14
  • Contributor
  • 136 replies
  • Answer
  • February 22, 2023

Seems like the sed statement isn't working as intended...I'd suggest the following:

system_profiler SPPowerDataType | grep "Maximum Capacity:" | cut -d ":" -f2

sdagley
Forum|alt.badge.img+25
  • Jamf Heroes
  • 3567 replies
  • February 22, 2023

Another caveat on that "system_profiler SPPowerDataType" command is that there's no "Maximum Capacity" in the output for non-laptop Macs.


Forum|alt.badge.img+2
  • Author
  • New Contributor
  • 1 reply
  • February 22, 2023

Seems like the sed statement isn't working as intended...I'd suggest the following:

system_profiler SPPowerDataType | grep "Maximum Capacity:" | cut -d ":" -f2

Thanks for the help!


mm2270
Forum|alt.badge.img+24
  • Legendary Contributor
  • 7886 replies
  • February 22, 2023

The wording in the output also seems to have changed between OS versions, because why would Apple keep anything consistent? On my MBP running Monterey 12.6.3 it shows as "Full Charge Capacity". I haven't checked, but my assumption is the "Maximum Capacity" label is from Ventura?

In short, unless you have one OS version across the board and only laptops, you might want to put some checks into the EA so it can correctly return a value when it runs. Like, check the OS version and modify the grep string, or just grep for ".* Capacity" maybe, and also check the model identifier (if you have any desktops in the mix) and return N/A or something for those. Otherwise they will return a blank result.