Listing non-admin accounts in OS X with dscl

423 Views Asked by At

Trying to write a Bash script that will pull all non-admin accounts into an array to which I can then remove the home directories rm -rf /Users/"$USER" and also delete the Sys Pref user dscl . -delete /Users/"$USER".

I can pull all admins with dscl . -read /Groups/admin GroupMembership | grep "$USER" | awk '{ print $3 }' but cannot figure out the command to pull non-admins.

Any help would be amazing!

1

There are 1 best solutions below

1
On

You might be able to go about this differently.

  1. Use dscl to read all users in the directory and store results

    dscl . list /Users

  2. Use your current dscl call to return all admin users. Store results separate from step one

  3. Loop through results from step 1 and, on each pass, loop through results from step 2.
  4. if the user of the main loop does not match any of admin users, execute your deletions against that user.