• 1. London, UK
  • 2. New York, NY
  • 3. Sydney, Australia
  • 4. Melbourne, Australia
  • 5. Paris, France
  • 6. Bangalore, India
  • 7. Amsterdam, Netherlands
  • 8. San Francisco, CA
  • 9. Hong Kong
  • 10. Houston, TX

Friday, September 23, 2005

 

HOW TO: Export all email addresses from a domain

Posted by Bharat Suneja at 8:16 AM
Background: AD Users & Computers 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 as csv/txt. However, any additional email addresses in the proxyAddresses attribute are not exported.

There's no GUI to list/export all email addresses. Here's a script to do that - ListEmailAddresses.vbs.


What does it exactly do?
- Queries Active Directory for Contacts & Groups
- Lists their email addresses
- Queries Users
- Lists enabled users' email addresses
- Lists disabled users' email addresses separately (was required for a certain project I did a long time back)
- Outputs to command line and also to a text file - c:\proxyaddresses.txt
- X.400 addresses are ignored

Updates:
08/07/2007: Download link updated to correct URL.

Labels: , , , ,

105 Comments:

January 11, 2006 9:28 AM
Blogger Seth said...

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

 
February 14, 2006 8:48 AM
Blogger boe said...

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

I also would like the exact same info as Seth.

Thanks!

 
April 27, 2006 9:20 AM
Anonymous Anonymous said...

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

 
May 19, 2006 12:58 PM
Anonymous Anonymous said...

sorry for the dumb question, but how do i run the ListEmailAddresses.vbs script? Thanks for the help or you can email me at oksetter@hotmail.com

 
May 19, 2006 1:33 PM
Blogger Bharat Suneja said...

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

 
May 19, 2006 1:53 PM
Anonymous Anonymous said...

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

 
June 15, 2006 7:27 AM
Blogger Farrukh Munir said...

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.

 
June 15, 2006 7:27 AM
Blogger Farrukh Munir said...

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.

 
June 15, 2006 7:27 AM
Anonymous Anonymous said...

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.

 
July 28, 2006 1:05 PM
Anonymous Anonymous said...

Would someone please send me the code to homeroarg@datafull.com ?!?
The links seems to be dead....

 
October 10, 2006 7:03 AM
Anonymous Anonymous said...

Excellent script, thanks a ton.

 
November 8, 2006 6:33 AM
Anonymous Anonymous said...

Great script thanks a lot.

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

thanks again

Al

 
November 9, 2006 10:24 AM
Anonymous WikAdmin said...

Thanks so much! This script is a life saver.

 
November 14, 2006 8:00 AM
Blogger Nehemoth said...

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

 
December 21, 2006 2:11 AM
Anonymous Anonymous said...

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

Ernie Nazario
enaz@spiritone.com
een@klarquist.com

 
January 17, 2007 6:47 AM
Anonymous Anonymous said...

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

 
February 19, 2007 7:51 AM
Anonymous Anonymous said...

Hello,

Any idea when it only produces results for 1000 records?

Richard

 
February 19, 2007 7:53 AM
Anonymous Anonymous said...

Any idea why it only produces 1000 records?

 
February 19, 2007 7:57 AM
Blogger Bharat said...

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.

 
February 23, 2007 2:11 PM
Anonymous Anonymous said...

Just a note of thanks for a very useful tool...

 
March 8, 2007 3:35 PM
Anonymous Anonymous said...

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

 
March 9, 2007 12:03 AM
Anonymous Anonymous said...

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

 
May 3, 2007 5:12 PM
Anonymous Anonymous said...

Doesnt work same error about line 54, 13 Null

 
May 8, 2007 6:44 AM
Anonymous Anonymous said...

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.

 
May 11, 2007 6:55 AM
Blogger Bharat Suneja said...

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

Bharat

 
May 30, 2007 7:48 AM
Blogger Ilan said...

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

Thanks !!

 
May 30, 2007 10:17 AM
Blogger Bharat Suneja said...

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

 
May 30, 2007 9:50 PM
Blogger Ilan said...

Great !!
looking forward for it :)

 
June 20, 2007 8:34 AM
Anonymous Anonymous said...

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!!!

 
June 27, 2007 9:52 AM
Blogger Bharat Suneja said...

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

 
July 30, 2007 6:57 AM
Anonymous Anonymous said...

I have recieved the following error msg:

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

Please advise.

 
July 30, 2007 7:31 AM
Anonymous Anonymous said...

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

 
August 7, 2007 3:44 PM
Anonymous Anonymous said...

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

Thanks,

Matthew

 
August 7, 2007 4:00 PM
Blogger Bharat Suneja said...

Matthew,

Thanks for pointing out - download link corrected.

 
August 29, 2007 9:39 AM
Anonymous Anonymous said...

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

 
September 3, 2007 4:37 AM
Anonymous Anonymous said...

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?

 
September 17, 2007 12:42 PM
Anonymous Anonymous said...

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

 
September 20, 2007 5:53 AM
Anonymous Anonymous said...

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

 
September 28, 2007 3:46 AM
Anonymous Anonymous said...

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

 
October 25, 2007 7:20 PM
Anonymous Anonymous said...

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.

 
November 19, 2007 9:42 AM
Anonymous Anonymous said...

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 ?

 
November 21, 2007 10:37 PM
Anonymous Anonymous said...

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

 
December 27, 2007 9:09 AM
Anonymous Anonymous said...

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

Regards,

Juan.

 
December 31, 2007 12:15 PM
Anonymous Anonymous said...

Thanks SO much! This is excellent.

 
January 3, 2008 7:41 AM
Anonymous Anonymous said...

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.
cdseawell@carilion.com

 
January 9, 2008 12:14 AM
Anonymous Anonymous said...

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.

 
January 16, 2008 9:31 AM
Anonymous Anonymous said...

Very nice list script, thank you.

Steve

 
January 31, 2008 7:31 AM
Anonymous Anonymous said...

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

 
February 17, 2008 6:29 PM
Anonymous Anonymous said...

Thanks Buddy,

Worked perfectly.

Jono.

 
March 4, 2008 1:20 PM
Anonymous Anonymous said...

THANK YOU!

 
March 24, 2008 7:49 PM
Anonymous Anonymous said...

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

 
March 25, 2008 4:48 AM
Anonymous Anonymous said...

Thank you, very helpful :)

 
April 2, 2008 2:29 PM
Anonymous Anonymous said...

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

 
April 7, 2008 3:38 AM
Anonymous Stewart said...

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!

 
May 13, 2008 5:15 AM
Blogger Thomas said...

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

 
May 26, 2008 11:15 PM
Anonymous Amidamaru said...

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

Please help

 
May 28, 2008 1:36 PM
Blogger snikki said...

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

 
June 4, 2008 1:58 AM
Anonymous CptRoger said...

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)

 
June 13, 2008 8:47 AM
Anonymous Anonymous said...

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

 
August 10, 2008 8:04 PM
Anonymous Rodney said...

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

 
August 12, 2008 8:51 AM
Anonymous Anonymous said...

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

 
August 28, 2008 2:27 AM
Blogger Frost Hon said...

Wonderful script, thank you very much. Appreciate it.

 
August 28, 2008 5:17 AM
Anonymous Anonymous said...

Thank, works great !

 
September 3, 2008 10:15 AM
Anonymous Anonymous said...

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.

 
October 7, 2008 5:30 AM
Anonymous Anonymous said...

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

 
October 7, 2008 4:25 PM
Blogger Bharat Suneja said...

@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)... :)

 
October 23, 2008 1:25 AM
Blogger a_patch said...

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

Thanks

 
November 24, 2008 2:27 AM
Anonymous Anonymous said...

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 ?

 
November 25, 2008 9:18 AM
Blogger David said...

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


---Feels like Home---

 
December 1, 2008 3:21 AM
Anonymous Anonymous said...

Great script! Works like a charm.

Thanks for sharing

 
December 3, 2008 9:21 PM
Anonymous Anonymous said...

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

 
December 12, 2008 12:41 PM
Anonymous Anonymous said...

Thanks so much! Saved me hours.

 
January 7, 2009 1:52 PM
Anonymous Another David said...

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?

 
January 7, 2009 4:40 PM
Blogger Bharat Suneja said...

@Another David: The script picks up your AD path by querying AD for RootDSE. You generally don't need to edit anything to run it.

See Serverless Binding and RootDSE for more info.

 
January 8, 2009 1:24 PM
Anonymous Mario_Andres said...

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

 
January 21, 2009 10:46 PM
Anonymous Anonymous said...

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

 
February 15, 2009 2:02 AM
Anonymous Jens said...

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

 
February 24, 2009 6:34 AM
Anonymous Anonymous said...

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

 
February 27, 2009 9:37 AM
Anonymous Anonymous said...

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.

 
April 29, 2009 12:04 PM
Blogger everton_rusch said...

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

 
May 7, 2009 2:20 AM
Anonymous Anonymous said...

Great script worked a treat! many thanks

 
May 7, 2009 11:51 PM
Anonymous Anonymous said...

Hi,

Really like the script. thanks!!!

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

Kind regards,

M

 
May 13, 2009 6:23 AM
Anonymous Anonymous said...

Brilliant.

Thanks very much.

 
May 27, 2009 7:26 AM
Blogger alouhichi said...

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,

 
June 1, 2009 8:02 PM
Anonymous טכנאי מחשבים said...

Great script thanks a lot.

 
June 11, 2009 7:21 AM
Anonymous Bob said...

Sweet, thanks for sharing this script!

 
July 2, 2009 10:00 AM
Blogger Michael said...

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?

 
July 11, 2009 1:26 PM
Blogger Bharat Suneja said...

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

 
September 25, 2009 2:15 AM
Anonymous Anonymous said...

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

 
September 29, 2009 12:20 PM
Anonymous תיקון מחשב said...

really great script! you helped me a lot.

 
October 6, 2009 12:48 PM
Anonymous Anonymous said...

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

-- Campbell

 
October 6, 2009 12:50 PM
Blogger Bharat Suneja said...

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

 
October 12, 2009 12:34 PM
Anonymous Anonymous said...

well, never work for me

 
October 20, 2009 8:59 AM
Anonymous Anonymous said...

Thanks a bunch, it still works perfectly

Jan

 
November 26, 2009 1:32 AM
Anonymous Oliver Fisk said...

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

 
December 2, 2009 9:26 PM
Anonymous Anonymous said...

Excellent script, thank you for your efforts!

 
December 11, 2009 3:17 PM
Blogger traderbob.nc said...

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

 
December 11, 2009 3:27 PM
Blogger traderbob.nc said...

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.

 
December 16, 2009 10:14 AM
Anonymous Battman said...

It's a great script, thanks.
I made a slight modification to include public folders also.
Modify line 38 near this part:
(objectClass=contact)(objectClass=group)
Change it to look like this:
(objectClass=contact)(objectClass=group)(objectClass=publicfolder)
It works on Windows2008/Exchange2007...
Cheers

 
December 16, 2009 10:25 AM
Blogger Bharat Suneja said...

@Battman: Thanks for the update!

 
January 14, 2010 3:50 AM
Anonymous Anonymous said...

Perfect, just perfect. Look for the text file in C:

 
January 26, 2010 1:15 AM
Anonymous Anonymous said...

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

 
January 29, 2010 5:09 AM
Anonymous Anonymous said...

U da man!!!

 
February 17, 2010 11:22 AM
Anonymous small business said...

Thanks for the info! This is what I needed!

 
February 18, 2010 3:52 PM
Anonymous Small Business said...

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

 

Post a Comment

Links to this post:

Create a Link

<< Home