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

    Hi All,

    I have an exchange question, but is unrelated to this specific topic. I was wondering if anyone here could assist or suggest a good place where I could get some assistance.

    A friend of mine has a Small Business Server 2003 machine that he was using for several years for his business. He has since closed the business and set aside his machine. Now he needs to get his emails from his account off his old server.

    How can he export his old emails from the database on the exchange server 2003 to something (I guess a .pst file), that he can import into his current outlook program, which seems to only have some of his latest emails, and not all of them from the previous set of years. As far as I know since the company was fairly small, there was never any archived and removed emails., They should all be there.

    Thank you in advance for your consideration and support.

    I can be reached at KShapiro-at-Bigfoot-dot-com. (Obviously replace the “-at-” with “@”, and “-dot-” with “.”

    Sincerely,
    Kevin Shapiro

  2. Anonymous

    Thank you, very helpful :)

  3. Anonymous

    Dood.. You rock, you just saved me hours worth of work. Much appreciated.

  4. Stewart

    I also get the (54, 13) (null): 0x80005000 error.

    This is from running the script as is without changing any of the contents.

    I know what my distinguished name is. Do I have to change the code in some way by physically inserting the distinguished name somewhere so it wull run?

    Any help to get this running so I can impress my boss greatly appreciated!

  5. Thomas

    Thanks for the script, but I’m getting the error: C:\ListEmailAddresses.vbs(52, 13) ADODB.Recordset: Item cannot be found in the collection
    corresponding to the requested name or ordinal.

    I’ve adjusted / entered my distinguishedName.

    Any help would be appreciated!

    Thanks,
    Tom

  6. Amidamaru

    I’ve got the same message
    Item cannot be found in the collection
    corresponding to the requested name or ordinal.

    Please help

  7. snikki

    What needs modified in this script to allow it to capture this data? I am new to scripting…

  8. CptRoger

    PERFECT!

    Shows the primary smtp address and all other smtp addresses (aliases) in the domain on a per user basis

    Thanks a lot!

    (for above, usage:
    – Unzip and enter this in command prompt:

    cscript C:\ListEmailAddresses\ListEmailAddresses.vbs > c:\bla.txt)

  9. Anonymous

    This script is great, particularly usefull if you need to set up mail archiving solutions on a well established domain. Many thanks, Carlton, UK

  10. Rodney

    Thanks a tonne. You’ve really helped me out. :-)

  11. Anonymous

    Hi,

    Great script, but I too am getting this error:

    "error: ADODB.Recordset: Item cannot be found in the collection
    corresponding to the requested name or ordinal."

    The path in AD I wish to output is:

    nonprofit.lib.mo.us > Microsoft Exchange Security Groups > Employee Exchange group

    I have modded the "distinguishedname" as follows:

    strUserDN = objRecordSet.Fields("OU=Employee Exchange group,OU=Microsoft Exchange Security Groups,DC=NONPROFIT,DC=LIB,DC=MO,DC=US") 'Get User's distinguished name from Recordset into a string
    set objUser= GetObject("LDAP://"& strUserDN & "")

    What have I done wrong?

    Thanks

  12. Frost Hon

    Wonderful script, thank you very much. Appreciate it.

  13. Anonymous

    Thank, works great !

  14. Anonymous

    This script worked great for most server. I noticed that if I had an OU called the same as the domain I got ListEmailAddresses.vbs(100, 13) (null): 0x80005000 error.

    Just did not get it to work on that OU.

  15. Anonymous

    How’s it going with also listing the e-mail addresses of the Public Folders? :)

  16. Bharat Suneja

    @Anonymous: Haven’t had the time to pick up the Public Folders part yet…

    I’m scratching my head as I think about VBScript again (given how easy this is using Exchange shell/Powershell in Exchange 2007)… :)

  17. a_patch

    Brilliant idea, wonderful script. MS should learn from you.

    Thanks

  18. Anonymous

    Excellent tool, ran on test environment (few users) worked perfectly. But on production where I have alot more users i get the ListEmailAddresses.vbs(55, 13) (null): 0x80005000, even with the following objCommand.Properties(“Page Size”) = 5000

    any advice what i need to do ?

  19. Dave

    Awesome, thanks for this script it has saved me from a big headache, and hours of tedious work.

    —Feels like Home—

  20. Anonymous

    Great script! Works like a charm.

    Thanks for sharing

  21. Anonymous

    To fix the (null): 0x80005000 error, you have to insert the following line in 2 places:

    strUserDN = Replace(strUserDN, “/”, “\/”)

    You have to add it after line 53 and the other line that says: strUserDN = objRecordSet.Fields(“distinguishedName”)

    You have to do this because some domains (like mine) have global groups with the / characters in them and that will cause the query to fail.

    Check out this article for the explaination:
    http://www.tek-tips.com/viewthread.cfm?qid=775481

    Enjoy

  22. Anonymous

    Thanks so much! Saved me hours.

  23. Another David

    I’m sorry, I’m still back with Stewart on 4/7/2008.

    Are we supposed to edit the script to define our specific
    “distinguishedName”? And if so, where and how?

  24. Mario_Andres

    Thanks you very much… great script. I also modified it to
    pull all public folders proxy address….

  25. Anonymous

    bravo! thx for sharing this tool, it fixed all my headache!

  26. Jens

    This works perfectly. I wonder why there is no such function accessible via GUI in Exchange Server. Thanks a lot!

  27. Anonymous

    thank you very much!!!!!!!!

  28. Anonymous

    I've been using cygwin with adfind for a while now, and it's easy to come up with commands to assist with AD management.

    To get all the email addresses from a domain:

    adfind -default -f "(objectcategory=user)" mail | grep @ | sed -e 's/>mail: //g' | sort

    You could also output the results to a file.

    There probably is an easier way with adfind to do that, but this has worked for me.

  29. everton_rusch

    Adfind is a great tool.

    But for the same funcionality of vbscript, try this:

    adfind -default -f "(objectcategory=user)" proxyAddresses | grep @ | sed -e 's/>mail: //g' | sort

  30. Anonymous

    Great script worked a treat! many thanks

  31. Anonymous

    Hi,

    Really like the script. thanks!!!

    But how do I add the user’s loginname to this???

    Kind regards,

    M

  32. Anonymous

    Brilliant.

    Thanks very much.

  33. alouhichi

    Hello,

    Exchange 2007 :
    Is there a way to show E-mail adresses (SMTP / proxy )in all public folders, even Hidden ?
    And where I can find the Folder.
    No Succes with : Get-MailPublicFolder | select Name,EmailAddresses

    Thanks,

  34. Bob

    Sweet, thanks for sharing this script!

  35. Michael

    For marketing purposes I'd like to crawl through the exchange server and get all *external* email addresses that our local users are sending / reciving from. If I had those in a CSV, I could write a vba routine to weed out the valid marketing contact. How do I do this?

  36. Bharat Suneja

    @Michael: This info can be found in message tracking logs.

  37. Anonymous

    gr8 script ….. thanks much for your time and supports..keep going guys… realyy doing great help!!!!!!!!!!!!!!!!!!!!

  38. Anonymous

    Thought you should know, your script is still coming in very handy. Thank you. It worked beautifully.

    — Campbell

  39. Bharat Suneja

    @Campbell: Thanks! This was one of my favorites when I wrote it a few years ago.

  40. Anonymous

    well, never work for me

  41. Anonymous

    Thanks a bunch, it still works perfectly

    Jan

  42. Oliver Fisk

    Great script. Ran perfectly first time. Great output. Thanks for putting this out there.

  43. Anonymous

    Excellent script, thank you for your efforts!

  44. traderbob.nc

    Excellent – thanks for the script – I kept getting error messages too until I edited the script as the anonymous poster noted on 12-3-08 9:21P
    to insert the line strUserDN=Replace(strUserDN,"/","\/") after line 53 and the other line that says strUserDN=objRecordSet.Fields ("distinguishedName")
    Then your script worked like a charm.
    It took me the better part of a day to figure out after reading all these posts and trying a bunch of stuff – I'm not a scripting expert so it probably took me a little longer than the average scripter
    Thanks again

  45. traderbob.nc

    Thanks for the script. It works great. The only problem I had was the same Line 54 char 13 I see other people having… and the ADODB.Recordset error.
    I inserted the string strUserDN = Replace(struserDN,"/","\/") after line 53 and after the line that says strUserDN=objRecordSet.Fields("distinguishedName")
    Thanks for the script. It took me a little longer to diagnose and fix the errors than the average scripter – because I am not as experienced with scripting.
    Thanks for the script.

  46. Anonymous

    Great work. You have saved me a lot of time and effort

Leave a Comment

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