Skip to content

Instantly share code, notes, and snippets.

@talkingmoose
Created August 26, 2020 22:29
Show Gist options
  • Save talkingmoose/5f5b1819ae2bcb4ccd2a047c9616e3a1 to your computer and use it in GitHub Desktop.
Save talkingmoose/5f5b1819ae2bcb4ccd2a047c9616e3a1 to your computer and use it in GitHub Desktop.
Report if any macOS user accounts with admin privileges exist.
#!/bin/bash
# list all users with UIDs above 501
usersList=$( /usr/bin/dscl . -list /Users uid | /usr/bin/awk '$2 >= 501 { print $1 }' )
# test for admin
while IFS= read aUser
do
/usr/sbin/dseditgroup -o checkmember -u "$aUser" admin 1>/dev/null
if [[ $? = "0" ]] ; then
echo "<result>Yes</result>"
exit 0
fi
done <<< "$usersList"
echo "<result>No</result>"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment