Last active
October 24, 2022 21:01
-
-
Save talkingmoose/e0536816d0982a0a6f33afe3c652c69f to your computer and use it in GitHub Desktop.
Removes all users with UIDs greater than 500 from local admin group.
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 | |
# these local accounts will not be removed from admins | |
# one account name per line; keep the beginning and closing quotes | |
exceptionsList="talkingmoose | |
bill.smith | |
oszein | |
jamfadmin" | |
# list all users with UIDs greater than or equal to 500 | |
localUsers=$( /usr/bin/dscl /Local/Default -list /Users uid | /usr/bin/awk '$2 >= 500 { print $1 }' ) | |
echo "List of local accounts: | |
$localUsers\n" | |
# remove all but those in exceptions list from local admins group | |
while IFS= read aUser | |
do | |
if [ ! $( /usr/bin/grep "$aUser" <<< "$exceptionsList" ) ] ; then | |
/usr/sbin/dseditgroup -o edit -d "$aUser" -t user admin | |
echo "Removed user: $aUser from admins group" | |
fi | |
done <<< "$localUsers" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment