Remove all disabled users from distribution lists

Cause of company policy we don’t delete users which are leaving, but we disabled them. The exchange mailbox will be removed after some months. For this incomming mails have to be forwarded to an exchange contact with an unresolvable address, so the sender receives an error message.

Cause of this, we need to remove the disabled users from all distribution list. If not, senders receive error messages each time a message was send to a distribution list with disabled users.

To automate this, i wrote a script. You can filter it by OU and run it first in a display-only mode before you remove the disabled users definitely from all distribution lists.

You can download the script RemoveDisabledUsers.vbs or copy/paste it from here:

9 thoughts on “Remove all disabled users from distribution lists”

  1. Hi,
    I’m looking for something similar. In my case I want to search for disabled users who are owners of distribution list so we can change ownership.

    Any help is appreciated.

    • Hello Jose

      You can run the script like this:
      cscript RemoveDisabledUsers.vbs > list.txt
      Then you will get a text-file with all disabled users, which are in distribution lists.

  2. After running I got an error: ” The size limit for this request has exceeded”.
    Will the script actually remove the owner of the DL? Because even after we remove disabled accounts from DL’s a Disabled user can still be the owner of it.

      • Actually no more error.

        Rather than doing a full AD query for all users, I changed it to look for the currently selected user.

        I’m sure it can be a lot cleaner, and/or even simpler to just search the groups the user is currently a member of, but that’s out of my depth of knowledge.

        Again, great script. Will continue to check back and see what other kind of cool tricks you come up with.


Leave a Reply