Skip to content

Instantly share code, notes, and snippets.

@talkingmoose
Last active May 31, 2023 16:45
Show Gist options
  • Save talkingmoose/2310bfc1f52f99c63e3db124613a9b30 to your computer and use it in GitHub Desktop.
Save talkingmoose/2310bfc1f52f99c63e3db124613a9b30 to your computer and use it in GitHub Desktop.
Jamf Pro extension attribute to list all Active Directory users on a computer.
#!/bin/zsh
adUsers=""
# get list of usernames
userList=$( /usr/bin/dscl . list /Users UniqueID | /usr/bin/awk '$2 > 500 { print $1 }' )
# create list of Active Directory usernames
while IFS= read aUser
do
if [[ $( /usr/bin/dscl . read "/Users/$aUser" OriginalAuthenticationAuthority 2>/dev/null) ]]; then
adUsers="$adUsers
$aUser"
fi
done <<< "$userList"
# remove blank lines from list of Active Directory usernames
adUsers=$( /usr/bin/sed -e '/^$/d' <<< "$adUsers" )
# submit userList to Jamf Pro
if [[ "$adUsers" ]]; then
echo "<result>$adUsers</result>"
else
echo "<result>No Active Directory accounts</result>"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment