HOW TO: Export all email addresses from a domain

Background: The Active Directory Users & Computers (ADUC) UI lets you list the mail column for each object, which displays the default (SMTP) email address for objects. You can export the list from ADUC to a CSV/txt file. However, any additional email addresses in the proxyAddresses attribute are not exported.

There’s no GUI interface (in ADUC or ESM) to list or export all email addresses. Here’s a script to do that – ListEmailAddresses.vbs.

Download link updated to non-HTTPS.

What does it exactly do?

  1. Queries Active Directory for Contacts & Groups
  2. Lists their email addresses
  3. Queries Users
  4. Lists enabled users’ email addresses
  5. Lists disabled users’ email addresses separately (was required for a certain project I did a long time back)
  6. Outputs to command line and also to a text file – c:\proxyaddresses.txt
    X.400 addresses are ignored

Related Posts

Written by

Bharat Suneja

143 Comments

  1. Anonymous

    U da man!!!

  2. small business

    Thanks for the info! This is what I needed!

  3. Small Business

    I recently came across your blog and have been reading along. I thought I would leave my first comment. I don't know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.
    Thank you,
    Paige

  4. Anonymous

    i get an error on line 54 char 13 anyone know why

  5. Anonymous

    Last anonymous – see the comment from December 11, 2009 from Traderbob.nc

    You likely have a user or group name with a "/" in it. The line from the above comment must be added at line 54 and again at line 101.

    It is a right useful script. I do need to hack at it to get it to enumerate public folders and other Exchange Recipient objects.

  6. Anonymous

    Great script. Amazing that Exchange Management Console doesn't offer this (and other equivalent) functionality.

  7. Ricardo Santos

    Thank you so much, it was a great help!!!

    Here's the condition I used to get only the PRIMARY e-mails:

    If Left (ProxyAddress,5) = "SMTP:" Then
    strResult = strResult & VbCrlf & proxyAddress
    AddressCount = AddressCount + 1
    End If

    Thank you!!
    http://www.santosalves.com

    1. Jesse

      Ricardo, Where did you insert the code you used to filter for only primary? I tried putting it just before the text file gets created but that didn’t work, although I received no error.

  8. Anonymous

    Hi there fantasic blog and script, I have no idea regarding scripting, I have looked into the code to see if I could modify it but it really isnt clear for me! I need to add atleast the ‘Title’ attribute from the organisation tab in AD and it would be great if I could also add the ‘Department’ and ‘Company’ attributes to the output, per user. If it is fairly straigh forward to do could somebody post the amended code or point me in the direction of which sections need modifying to do this. Thanks very much and have a great weekend. Keith

  9. Jose

    The mailbox which i disabled is not showing in the Disconnected mailboxes. I have checked the settings under: Mailbox Database Properties -> Limits -> Keep deleted mailboxes for(Days)=30. Can’t figure out how the mailbox disappeared. Now, I want the mailbox as needs to refer to very important emails from it. Can Anyone help…. please?????? Jose Fernz…

  10. Lars Petersson

    Great script. Unfortunately it only returns a bit under 500 results for me, and we have much more than that here…

    There are no errors though…

  11. Steve Cooper

    great little script. saved hours of work.
    Don’t suppose you know of a utility to globally change users passwords in AD by taking info from a pre-selected list

  12. GeekChick

    THANK YOU!!!! I needed a list of email addresses to import. This worked like a champ.

  13. dspanic

    Is it possible in list to add size of email?

  14. VaartM

    greate script

  15. Suneth

    What are the lines i have to edit to get email address.
    if my domain is ‘mydomain.com’

    i change line 54
    “LDAP://mydomain.com/”& strUserDN & “”

    i change line 100
    set objUser= GetObject(“LDAP://mydomain.com/”& strUserDN & “”)

    but still it gives error message that
    ‘The specified domain either does not exit or …”

    please help

    1. Matt

      Suneth, you shouldnt need to edit the script. just download and extract. Run on the server and then close the script output window. On the root of the c drive you should see a text file called proxyaddresses.txt open this and you should see the list of the users with email addresses listed under them.

      When SMTP is in CAPS this shows that it is the primary SMTP mail address.

  16. Jon

    Awesome script… Taking it one step further… Could this be used in conjunction with something else to take any disabled users with an email address and CLEAR it out…… We are running into an issue with disabled users retaining their email address even though their mailbox was deleted. That is messing up our Mimecast.
    Thanks in advance…

  17. chuck

    You rock dude!

  18. Eric Ramljak

    Awesome script, saved much time.
    Thanks for your work

  19. Pal Amundsen

    Thank you! Just what I needed :-)

  20. MOHAMMED

    Hi Every one im not like u guys… i assigned work to pull up 960 users email address from AD and update them in Excel file.. can any one help me how to get there email address in a easy way inspite of pulling every ones account and copy the email address…
    And users are from diff locations and account/ domains..from US

  21. shawn

    The size limit for this request was exceeded

    The script returns the above error. This is a very large domain in excess of 40,000 users. Any way to modify the script to return more results?

  22. Nicholas Callahan

    When I run your script I get a Windows Script Host error. It says:

    Line: 158
    Char: 6
    Error: The size limit for this request was exceeded
    Code: 80072023
    Source: Provider

    Do you have how to get your script to download the whole directory?

    1. Michael K

      I have the same question about Line 158, char: 6. Any fix for this?

  23. Jason M

    Pretty new to this, so I’m sure I’m doing something wrong. I downloaded this script, copied it to my domain controller and double clicked it. Nothing happened…no errors, no proxyaddresses.txt on the C:\ How am I supposed to run this script exactly?

  24. Shariful

    can anyone suggest any solution/software, by which i’ll be able to get email addresses from certain domains? not such email address generators which only generates emails from hotmail or yahoo….such as, if i’d like to generate email address, which are associated with http://www.smsi.se ….any idea will be welcome.

  25. Sandeep

    Hi
    I am trying to download the script but server is timing out…can you please email or send us another link to download

    1. Matt

      Sandeep: the link redirects you to the https (secure) version of Exchangepedia. Just remove the ‘s’ from ‘https’ and it’ll download fine.

  26. Javier

    Hi im very interested to hiring somebody else, to help me to set this script as i want. please send me an email to [email protected]

  27. aaron

    What a fantastic tool!
    Makes migration much easier.

  28. Serg

    eeemail.net – exports all email contacts and all email addresses ever met at your mailbox (gmail, yahoo , etc ). free

  29. Data Recovery

    Hi,

    Thanks for this interesting and helpful script!

  30. Dan

    nice script!! Did exactly what i needed and it still works. Just be sure to put the file in the root of the c:\ so that it can create the necessary .txt file in that same location

  31. Ldifde Export |

    […] HOW TO: Export all email addresses … – Exchange Server and Active Directory management tools don’t have a GUI tool to export all email addresses from a domain/Exchange Server. The … […]

  32. Berra

    When I run your script I get a Windows Script Host error. It says:

    Line: 79
    Char: 6
    Error: The size limit for this request was exceeded
    Code: 80072023
    Source: Provider

    Do you have how to get your script to download the whole directory?

    1. Bharat Suneja

      @Berra, This is pretty old and written in VBScript. You should be using PowerShell on current systems.

      Either way, just search for the error on Bing/Google and you’ll find instructions/script block you can add to this script to set a higher query limit.

      If you’re using PowerShell, it’s much easier.

Leave a Comment

Your email address will not be published. Required fields are marked *