Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save talkingmoose/ce414309887fa208c7b142688c697dce to your computer and use it in GitHub Desktop.

Select an option

Save talkingmoose/ce414309887fa208c7b142688c697dce to your computer and use it in GitHub Desktop.
Jamf Pro extension attribute to read macOS accounts with active Apple Accounts
#!/bin/zsh
# create a list of local usernames (non-AD) with UIDs between 500 and 1024
usernames=( $( /usr/bin/dscl /Local/Default -list /Users uid | /usr/bin/awk '$2 >= 501 && $2 <= 1024 { print $1 }' ) )
for aUser in $usernames
do
echo "Evaluating user account $aUser"
# get home directory for user account
homeDirectory=$( /usr/bin/dscl . read "/Users/$aUser" | /usr/bin/awk -F ": " '/NFSHomeDirectory/ { print $2 }' )
# get logged in Apple Account (if any)
appleAccount=$( /usr/bin/defaults read "$homeDirectory/Library/Preferences/MobileMeAccounts.plist" | /usr/bin/awk -F '"' '/AccountID/ { print $2 }' )
#compile results
if [[ "$appleAccount" ]] ; then
results=$( echo -e "$aUser: $appleAccount\n$results" )
else
results=$( echo -e "$aUser: No Apple Account\n$results" )
fi
done
# remove empty line from results
results=$( /usr/bin/tail -r <<< $results )
echo "<result>$results</result>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment