Remove user from all groups via command line
Posted on 2008-11-07
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!