Delete all admin user except administrator

I would like to delete all the users who have admin privileges except for a user named "administrator"

dscl . -delete /Groups/admin

I think the above command will delete all admin users, but is there a way to edit the command to accomplish what I want.


You need to iterate over all users in the admin group, deleting them one by one, leaving your chosen account alone as opposed to deleting the admin group itself.

Also, use care to not delete any built in accounts since that would break your os. Typically user accounts have ID greater than 500 so you’ll piece together a bit of scripting:

  • https://superuser.com/questions/279891/list-all-members-of-a-group-mac-os-x

I’m not going to post a working script since you’ll want to carefully craft your deletion to be reversible and also clean up user home folders after you delete each user. Making an error on that script could cause substantial data loss.