HOW TO: Export all email addresses from a domain

by Bharat Suneja

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

{ 50 comments… read them below or add one }

Seth January 11, 2006 at 9:28 am

This program looks really great, I only have two questions and before i ask I would like to thank you for your hard work and thank you again very much for your time and help, I do indeed appreciate it VERY MUCH. Ok, having said that here are my questions.
1) IS ther a way to pipe the output to text? I do not seem to have figured out the correct way, I always get a 0 byte file with my standard filename.vbs > filename.txt procedure. 2) Is there a way to modify it so I get all smtp address? I seem to only get the Proxy addresses which are usually secondary, also is there a way to get help with the program? a /? did not do that for me –
Again I appreciate your time and help in this,

Seth Roth

Reply

boe February 14, 2006 at 8:48 am

I agree with Seth – thanks so much for your hard work.

I also would like the exact same info as Seth.

Thanks!

Reply

Anonymous April 27, 2006 at 9:20 am

the program dump information

‘Output to a text file
Set objFileSystem = CreateObject(“Scripting.FileSystemObject”)
Set objOutputFile = objFileSystem.CreateTextFile(“C:\proxyaddresses.txt”)
objOutputFile.Write strResult

C:\proxyaddresses.txt look there

Reply

Anonymous May 19, 2006 at 12:58 pm

sorry for the dumb question, but how do i run the ListEmailAddresses.vbs script? Thanks for the help or you can email me at [email protected]

Reply

Bharat Suneja May 19, 2006 at 1:33 pm

Run it from a command prompt. If cscript is not your default script host (and no harm done even if it is):
cscript scriptname.vbs

The script will generate a txt file in the root folder of your c:\ drive – c:\proxyaddresses.txt – as noted in one of the previous comments as well.

Bharat

Reply

Anonymous May 19, 2006 at 1:53 pm

awesome..thanks so much. Saved me a call to Microsoft techsupport on how to output all SMTP addresses to a txt file.

Reply

Farrukh Munir June 15, 2006 at 7:27 am

I am facing one problem that how I can get the internal email (through exchange server) address from my outlook.for example I got the email and I just want to figure out only “From” (received email)

exchange server used x400 protocol and I can not get only sender email address..if anyone has idea about it then please do send me piese of code.

Reply

Anonymous June 15, 2006 at 7:27 am

I am facing one problem that how I can get the internal email (through exchange server) address from my outlook.for example I got the email and I just want to figure out only “From” (received email)

exchange server used x400 protocol and I can not get only sender email address..if anyone has idea about it then please do send me piese of code.

Reply

Farrukh Munir June 15, 2006 at 7:27 am

I am facing one problem that how I can get the internal email (through exchange server) address from my outlook.for example I got the email and I just want to figure out only “From” (received email)

exchange server used x400 protocol and I can not get only sender email address..if anyone has idea about it then please do send me piese of code.

Reply

Anonymous July 28, 2006 at 1:05 pm

Would someone please send me the code to [email protected] ?!?
The links seems to be dead….

Reply

Anonymous October 10, 2006 at 7:03 am

Excellent script, thanks a ton.

Reply

Anonymous November 8, 2006 at 6:33 am

Great script thanks a lot.

do you know how we can also generate emails for public folders?

thanks again

Al

Reply

WikAdmin November 9, 2006 at 10:24 am

Thanks so much! This script is a life saver.

Reply

Nehemoth November 14, 2006 at 8:00 am

first Thank you for the script.

I wanna know how can i change it, so that list me the smpt emails to a file and also from just one specific organization unit.

Regards

Reply

Anonymous December 21, 2006 at 2:11 am

I recieve an error when running this script;
Line 54 char 13. What could be the problem.

Ernie Nazario
[email protected]
[email protected]

Reply

Anonymous January 17, 2007 at 6:47 am

I also get an error (54, 13) when running the script. Any ideas?

Reply

Anonymous February 19, 2007 at 7:51 am

Hello,

Any idea when it only produces results for 1000 records?

Richard

Reply

Anonymous February 19, 2007 at 7:53 am

Any idea why it only produces 1000 records?

Reply

Bharat Suneja February 19, 2007 at 7:57 am

You can increase the “page size” – this is the number of records ADSI returns from an AD search – by adding the following code before objcommand.execute:

objCommand.Properties(“Page Size”) = 2000

(Set it to number of records you want to return…).

I will modify the script soon to move through “pages” without having to set a pagesize for different environments.

Reply

Anonymous February 23, 2007 at 2:11 pm

Just a note of thanks for a very useful tool…

Reply

Anonymous March 8, 2007 at 3:35 pm

My first and only cscript attempt failed with the following error, any ideas?

C:\TEMP>cscript ListEmailAddresses.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

C:\TEMP\ListEmailAddresses.vbs(54, 13) (null): 0x80005000

Reply

Anonymous March 9, 2007 at 12:03 am

Perfect script! It’s a life saver.
Thanks,

Reply

Anonymous May 3, 2007 at 5:12 pm

Doesnt work same error about line 54, 13 Null

Reply

Anonymous May 8, 2007 at 6:44 am

Error list.vbs: (54, 13) (null): 0x80005000

When you look at line 54 it reads:
strUserDN = objRecordSet.Fields(“distinguishedName”)

You have to enter your “distinguishedName” for the script to work.
Now how to get it?
It’s fairly simple, Let’s assume your domain is called “example.local”, and the container with employees is called “Employees”

The distinguishedName in this case wil be “OU=Employees,DC=EXAMPLE,DC=LOCAL”

If you want to get the name for a subfolder “Employees->Accounting” your name would change to “OU=Accounting,OU=Employees,DC=EXAMPLE,DC=LOCAL”

Moreover, you can uncomment the fllowing lines (by removing ‘)
wscript.Echo strADPath

wscript.echo “objDomain: ” & objDomain.distinguishedName

to dissplay variables you’re looking for.

Reply

Bharat Suneja May 11, 2007 at 6:55 am

You can also get the distinguishedName of a given object from ADSIEdit.msc.

Bharat

Reply

Ilan May 30, 2007 at 7:48 am

Great script !!
any way to make it show the names for the public folders ?? (unicode enables too )

Thanks !!

Reply

Bharat Suneja May 30, 2007 at 10:17 am

Would need to add a loop for (objectClass=publicFolder). In addition to Public Folders, Query-Based Distribution Groups need to be added as well, if I remember correctly.

Both are on my list of things to do – perhaps this week.

Bharat

Reply

Ilan May 30, 2007 at 9:50 pm

Great !!
looking forward for it :)

Reply

Anonymous June 20, 2007 at 8:34 am

I have tried running this script many times and it won’t work for me. I have run it against different Exchange servers in fourdifferent domains. The first two clients it works fine without modifying the file. The other two it errors out stating line 100 is the problem. I have tried to modify the script for the two problem domains, but I can only get it to grab a couple addresses. There are well over 500 addresses in each of those domains. The only pattern I see is that the two clients that this worked for had Exchange servers named “Mail” and one of those two servers is also a DC. The other two clients have Exchange Servers named something like “ABCemail” neither being a DC. I have tried modifying the script for with the names of those servers, but it either works partially or not at all. PLEASE HELP!!!

Reply

Bharat Suneja June 27, 2007 at 9:52 am

The script queries Active Directory, so the names of Exchange servers aren’t really an issue here.

Reply

Anonymous July 30, 2007 at 6:57 am

I have recieved the following error msg:

ListEmailAddresses.vbs(100, 13) (null): 0x80005000

Please advise.

Reply

Anonymous July 30, 2007 at 7:31 am

Hi Bharat Suneja,

Your script looks very nice could you please tell me where I need to change the “distinguishedName” I have tried to change on line 54 but I receive this error:
C:\ListEmailAddresses.vbs(52, 13) ADODB.Recordset: Item cannot be found in the collection
corresponding to the requested name or ordinal.

Any help much appreciated,
Slr

Reply

Anonymous August 7, 2007 at 3:44 pm

Is it possible to repost the downloadable file as it appears not to be available any longer.

Thanks,

Matthew

Reply

Bharat Suneja August 7, 2007 at 4:00 pm

Matthew,

Thanks for pointing out – download link corrected.

Reply

Anonymous August 29, 2007 at 9:39 am

Thank you, thank you, thank you. Your a super star for the script :)

Reply

Anonymous September 3, 2007 at 4:37 am

Hi,
I get a script error when running it.
I get the screen with the results and al that stuff but after closing it I get the following error (in WSH): Line 167
Char: 1
Error: ActiveX component can’t create object: ‘Scripting.FileSystemObject’
Code: 800A01AD
Srouce: Microsoft VBScripting runtime error
After that I ofcourse do not get the txt file.
I tried it using Exchange 2003
Can anybody help me to correct the problem?

Reply

Anonymous September 17, 2007 at 12:42 pm

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

Reply

Anonymous September 20, 2007 at 5:53 am

Great script. Did you ever manage to get it to do Public Folders?

Reply

Anonymous September 28, 2007 at 3:46 am

Perfect. Does exactly what I wanted. Saves me a lot of time on a regulkar basis. Cheers! Karl

Reply

Anonymous October 25, 2007 at 7:20 pm

I get the same error message as others.

ListEmailAddresses.vbs(53, 13) ADODB.Recordset: Item cannot be found in the collection corresponding to the requested name or ordinal.

I have the correct distinguishedName for my domain in the script.

Reply

Anonymous November 19, 2007 at 9:42 am

hi, great script !!!
Just one question, the final text file en encoded ANSI and I need it RTF. Any idea how can I change the encoding of the file via the script ?

Reply

Anonymous November 21, 2007 at 10:37 pm

Thanks , Very great Script.
One question.
can you include the email addresses in public folders?

Reply

Anonymous December 27, 2007 at 9:09 am

Thanks for the script, it works. Saved me some time collecting this information.

Regards,

Juan.

Reply

Anonymous December 31, 2007 at 12:15 pm

Thanks SO much! This is excellent.

Reply

Anonymous January 3, 2008 at 7:41 am

This script worked great. Thank you very much. Is there a way to edit it so that it will do just the opposite and located all accounts in AD that do not have the email filled in?

Right now our company is using a mix of Novel and Windows. Because we use GroupWise as the primary email service, Exchange is not being used. We have several user accounts in AD that never had the email address field filled out because we use Novel. We need to run the script to capture those blank accounts and populate them later with their Novel GW email.

Thank so much.
[email protected]

Reply

Anonymous January 9, 2008 at 12:14 am

Is there a way to get the script to only output SMTP addresses, and create a file output file that is simply:

email
email
email

With no other formating or text.

Reply

Anonymous January 16, 2008 at 9:31 am

Very nice list script, thank you.

Steve

Reply

Anonymous January 31, 2008 at 7:31 am

Hello

I am trying to get the email address of an OU. It’s showing the error below.
(54, 13) ADODB.Recordset: Item cannot be found in the
ollection corresponding to the requested name.
Please advise

Reply

Anonymous February 17, 2008 at 6:29 pm

Thanks Buddy,

Worked perfectly.

Jono.

Reply

Anonymous March 4, 2008 at 1:20 pm

THANK YOU!

Reply

Leave a Comment

Previous post:

Next post: