Menu

#71 Removing users from DSCL

open
nobody
None
5
2012-10-09
2008-09-01
mikael
No

With 10.4 AJ could delete the netinfodatabase when you
liked to EnableNewSetup with 10.5 machines you must
delete them one by one with DSCL.

I have made it this way maybe that helps a little bit:
users500=dscl . list /users UniqueID | awk '($2>='500'){print $1}'

echo "Listing users with ID above 500 and their home directories:"
for users in $(dscl . list /users UniqueID | awk '($2>='500'){print $1}');
do (dscl . read /users/$users NFSHomeDirectory | sed -e 's/NFSHomeDirectory://');done;

echo "Enter the username that you want to delete, or just press Enter to quit [ENTER]:"
read name
if [[ "$users500" =~ "$name" ]]; then
echo -e "Confirm that you want to delete user "$name"" and the homedirectory,\nthats also a member of the following groups:
dscl . -list /groups GroupMembership | grep "$name" | awk '{print $1}'
else
echo "Is not a user with ID above 500, quitting..."
exit 1
fi

}

echo "Type 'yes' to confirm or 'no' to quit and then press [ENTER]:"
read input1
if [ "$input1" = "yes" ]; then
echo "Removing user "$name" ..."
for group in $(dscl . -list /groups GroupMembership | grep "$name" | awk '{print $1}');
do (sudo dscl . delete /groups/$group GroupMembership "$name" );done;
sudo rm /private/var/db/dslocal/nodes/Default/users/"$name".plist
sudo rm -r /Users/"$name" # maybe this shouldnt be i AJ for safety reason just like before.

Discussion


Log in to post a comment.

MongoDB Logo MongoDB