Last active
May 31, 2023 16:45
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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