A good extension attribute is worth it’s weight a thousand times over it if can save you time.

I’ve included here a collection of the extension attributes that I’ve collected/written for the Casper Suite that have saved me countless hours. Some of them are quite specific but hopefully they can be of use to you. If you have any questions or would like some help with writing a custom extension tweet me @jacobcurulli

Battery Health Status

#!/bin/sh
result=`ioreg -r -c "AppleSmartBattery" | grep "PermanentFailureStatus" | awk '{print $3}' | sed s/\"//g`
if [ "$result" == "1" ]; then
result="Failure"
elif [ "$result" == "0" ]; then
result="OK"
fi
echo "<result>$result</result>"

 

Java Version Installed

#Check if java_home is defined
javaHome=`/usr/libexec/java_home 2> /dev/null`;
if [ ! -z $javaHome ]
then
vers=`java -version 2>&1 | grep "java version" | awk '{print substr($3,2,length($3)-2);}'`
echo "<result>$vers</result>"
else
echo "<result>Not Installed</result>"
fi

 

Flash Version Installed

#!/bin/sh
result=`/usr/bin/defaults read /Library/Internet\ Plug-Ins/Flash\ Player.plugin/Contents/version CFBundleShortVersionString`
echo "<result>$result</result>"

 

Battery Serial Number

#!/bin/sh
battery='ioreg -r -c "AppleSmartBattery" | grep "BatterySerialNumber" | awk '{print $3}' | sed s/\"//g'
echo "<result>$battery</result>"

 

Firewall Status (on or off)

result=`/usr/bin/defaults read /Library/Preferences/com.apple.alf globalstate`
if [ "$result" == "0" ]; then
echo "<result>Off</result>"
else
echo "<result>On</result>"
fi

 

List all users on the local machine

# Get a list of users, filter out service accounts
users=`dscl /Local/Default -list /Users uid | awk '$2 >= 100 && $0 !~ /^_/ { print $1 }'`
# Output for extension attribute
echo '<result>'$users'</result>' 

 

List all admin users on the local machine

admin=`dscl . -read /Groups/admin GroupMembership`
#Output for extension attribute
echo '<result>'$admin'</result>'