Skip to main content
Question

Deleting non-standard Admin account

  • June 5, 2015
  • 3 replies
  • 27 views

roiegat
Forum|alt.badge.img+16

Anyone have a good script for delete a admin account that is above UID 500? We want to give the users the ability to enroll from the enrollment page with their initially created account, but after they enroll we want to kill all expect the one account we put in. Since were dealing with accounts here wanted to see if anyone had any good script for it.

3 replies

bpavlov
Forum|alt.badge.img+18
  • Esteemed Contributor
  • June 5, 2015

Not sure if you did a search but there was a very similar question asked earlier this week. I can't find it right now but did find this:
https://jamfnation.jamfsoftware.com/discussion.html?id=7584


roiegat
Forum|alt.badge.img+16
  • Author
  • Valued Contributor
  • June 5, 2015

Yeah did a couple searches but nothing fit the right way. My biggest fear is that somehow the account under UID 500 get sacked and then we got bigger problems. I'll keep looking.


Forum|alt.badge.img+2
  • New Contributor
  • June 5, 2015

Something quick and dirty I came up with to get you started:

#!/bin/bash

#get list of admins
admins=$(dscl . -read /Groups/admin GroupMembership | sed 's/GroupMembership: //')

#for each username in admins, check it's UniqueID, if it's known to be greater than 500, remove it.
for user in $admins; do
    userID=$(dscl . -read /Users/$user UniqueID 2> /dev/null | sed 's/UniqueID: //')
    if [[ ! -z "$userID" ]]; then
        if [[ $userID -gt 500 ]];then           
            #delete the user account via dscl
            echo "deleting user $user because it's an admin with a Unique ID:$userID greater than 500"
        else
            # keep the user
            echo "keeping user $user because it's Unique ID: $userID is less than 500"
        fi
    fi
done