Removing AD Users Remotely On Catalina

vbenthagen92
New Contributor

Hey all,

Quick rundown is that users log into the machines using Active Directory accounts and it creates a mobile account upon login.

What I am looking to do is delete the user cleanly while also removing the shared information. I am aware that I can use sysadminctl to remove the user and alot of the information to move forward. The current issue is that this wasnt done previously and was using dscl to remove the user and then an rm command to remove the home folder. I am currently trying to remove the remainder of the users off of the computer which is the SharePoint and Group in Directory Editor to clean these up to move forward without a complete image.

I can do it manually in terminal using the full filename. I will post what I am currently trying to use to remove the information. It may not be perfect but I am running into issues with the commands.

Please let me know if there is anything that can be done to correct this or any insight. Also if I have anything completely wrong please let me know as I am still fairly new to this side of things.

Much Thanks

#!/bin/sh

UserList=$( dscl . list /Users UniqueID | awk '$2 > 1000 {print $1}' )

echo "Deleting account and home directory for the following users..."

for a in $UserList ; do
    find /Users -type d -maxdepth 0 -mindepth 0 -name "*.*" -mtime +0 | grep "$a"
if [[ $? == 0 ]]; then
    echo $a
    dscl . delete /Users/"$a"  #delete the account
    rm -r /Users/"$a"  #delete the home directory
fi
done

dscl . -delete /SharePoints/*Folder #remove sharepoint
dscl . -delete /groups/com.apple.sharepoints* #remove from groups



exit 0
1 REPLY 1

johntgeck
Contributor

Hi there,

I realize this is an old thread but I thought I'd check in with you about this as I'm working on something similar and running into a weird issue. Here's what I've got --

# list all users with the "." character in their names
USERS=$( dscl . ls /Users | grep -e "\." )
# echo users
echo Deleting the following users: $USERS
# delete users
/usr/bin/dscl . delete /Users/"$USERS"
echo User accounts deleted
# delete home folders
/bin/rm -rf /Users/"$USERS"
echo User home folders deleted

My issue that I'm running into is that this seems to work pretty well (I am just searching for user accounts with "." in the name with my grep, nothing too fancy), but once I've done this, even after a reboot or a complete rebind to AD I can no longer sign in and create a new mobile account as a user that was removed in this way.

Where did you end up?