I am struggling to find a decent way to do this. For one reason or another (not important, it is what it is) we have a rather a lot of users who are disabled but are still a member of all of their pre-disable groups. This is causing a few issues such as distribution list failures, difficulty enumerating ACL's etc.
Does anyone know of an easy way to bulk remove groups from users that are disabled? For ease, they all exist in one container now so if its something that can be done on container level, that's useful. Also, I know we could delete the accounts, but for auditing and cross linking with our HR system, that is not possible.
This sample batch file will do what you're asking. You'll need to edit the
dsquery
command to use your specific StartNode OU -- TheOU=SomeOU,DC=example,DC=com
bit:Using Powershell and the Quest AD cmdlets available here, the following PowerShell script should do the trick -
I recently wanted to remove groups from (almost all) disabled users so I wrote my own set of functions in PowerShell v3 (which doesn’t require third-party software).
For composability and re-use, I first wrote a function to remove the specified user from all groups (aside from their primary group). I could add an option to specify the group type (Security or Distribution) but I don’t need that functionality at the moment.
I then used this function to remove all disabled users from all groups (other than their primary group). I use a search base so that an OU can be specified and I also have a list of default/system users who should not have their group membership changed.