Remove user from all groups from command line

Joined
Nov 7, 2008
Messages
2
Reaction score
0
Hey guys - 1st Post here.

I'm trying to automate a delete user script and I am stuck on trying to remove a user from all his group memberships.

We have several hundred different groups and a user may be a member of any number of them.

For almost every other function, I'm using the "net user" command. I've looked at the "dsmod" command and the "net group" command, but I don't see any way to automate finding which groups the user is a member of.

Here's the reasoning behind it - When we receive a delete request, we disable the user and keep the account around for 7 days in case they need anything from it or change their mind. In the meantime, we want to remove the user from all distribution groups so that people don't assume the user is still a member of the group. We also want the user account removed from security groups.

Any help would be appreciated! Thanks!
 
Ok, I figured it out myself - The command is DSQUERY GROUP | DSMOD GROUP -C -RMMBR "CN=Smith\, John,OU=SalesDepartment,OU=Users,DC=MyDomain,DC=com"

It goes through all the groups in the domain and tries to remove the user from it. The "-C" switch specifies that the command should continue on errors instead of stopping when it gets to the first problem.
 
Back
Top