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 Comments


  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.

    Reply

    1. 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.

      Reply

  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.

    Reply

  3. Josh.

    Great script.

    I’d like to use this script while my help desk staff are disabling user accounts via Active Directory Users and Computers. So, rather than searching for all users, I’d like to have this as part of the process for the currently selected user.

    Similar to this; http://deenaik.blogspot.com/2009/11/add-custom-field-to-aduc-employee-id.html

    I’ve tried to manipulate the script, but it seems to error out.

    Any ideas/suggestions?

    Reply

    1. What kind of error do you get?

      Reply

      1. 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.

        Reply

  4. Thanks a lot for this great script.

    Reply

Leave a Reply