Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Removes all users with UIDs between 500 and 1025 from local admin group.
#!/bin/sh
# list all users with UIDs between 500 and 1025
keepUsers=$( /usr/bin/dscl /Local/Default -list /Users uid | /usr/bin/awk '$2 >= 501 { print $1 }' )
# remove all but "ARD" and "IT" users from local admins group
while IFS= read aUser
do
if [[ "$aUser" != "ARD" && "$aUser" != "IT" ]] ; then
/usr/sbin/dseditgroup -o edit -d "$aUser" -t user admin
echo "Deleted user: $aUser."
fi
done <<< "$keepUsers"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment