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

{ 40 comments… read them below or add one }

Anonymous January 29, 2010 at 5:09 am

U da man!!!

Reply

small business February 17, 2010 at 11:22 am

Thanks for the info! This is what I needed!

Reply

Small Business February 18, 2010 at 3:52 pm

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

Reply

Anonymous April 4, 2010 at 7:19 pm

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

Reply

Anonymous April 5, 2010 at 6:27 pm

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.

Reply

Anonymous April 6, 2010 at 3:06 pm

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

Reply

Ricardo Santos April 23, 2010 at 4:25 am

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

Reply

Jesse January 12, 2011 at 1:33 pm

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.

Reply

Anonymous July 16, 2010 at 10:16 pm

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

Reply

Jose August 18, 2010 at 10:18 pm

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…

Reply

Lars Petersson August 25, 2010 at 5:31 am

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…

Reply

Steve Cooper September 14, 2010 at 8:05 am

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

Reply

GeekChick September 29, 2010 at 2:01 pm

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

Reply

dspanic December 29, 2010 at 2:02 pm

Is it possible in list to add size of email?

Reply

VaartM January 7, 2011 at 2:20 am

greate script

Reply

okika January 13, 2011 at 10:25 am
Exchange Recovery January 24, 2011 at 12:56 am

Hi,

Thanks for this interesting and helpful script!

Reply

Suneth February 18, 2011 at 10:13 pm

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

Reply

Matt February 28, 2011 at 4:12 am

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.

Reply

Jon April 21, 2011 at 7:17 am

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…

Reply

chuck May 4, 2011 at 2:45 pm

You rock dude!

Reply

Eric Ramljak June 28, 2011 at 6:57 am

Awesome script, saved much time.
Thanks for your work

Reply

Pal Amundsen September 22, 2011 at 5:48 am

Thank you! Just what I needed :-)

Reply

MOHAMMED October 17, 2011 at 1:38 am

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

Reply

shawn October 24, 2011 at 2:18 am

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?

Reply

Nicholas Callahan November 13, 2011 at 7:06 pm

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?

Reply

Michael K December 8, 2011 at 12:17 pm

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

Reply

Jason M January 3, 2012 at 2:08 pm

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?

Reply

Bharat Suneja January 3, 2012 at 5:58 pm

Open a command window (Start > Run > Cmd), use CSCRIPT to run a script (or you can also set default script execution engine to CSCRIPT).

Reply

Shariful March 14, 2012 at 6:21 am

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.

Reply

Sandeep April 27, 2012 at 6:49 pm

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

Reply

Matt May 18, 2012 at 5:13 pm

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

Reply

Hayden kirk May 17, 2012 at 5:18 pm

I have put a link up as I needed the file as well. Lucky I still had it on another server.

http://www.layer3.net.nz/files/AddressList.zip

Cheers.

Reply

Javier June 13, 2012 at 11:10 am

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]

Reply

aaron June 21, 2012 at 6:36 pm

What a fantastic tool!
Makes migration much easier.

Reply

Serg June 22, 2012 at 6:40 am

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

Reply

Data Recovery April 8, 2013 at 1:48 am

Hi,

Thanks for this interesting and helpful script!

Reply

Dan July 15, 2013 at 2:41 pm

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

Reply

Berra January 23, 2018 at 10:42 pm

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?

Reply

Bharat Suneja January 29, 2018 at 7:03 pm

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

Reply

Leave a Comment

{ 3 trackbacks }

Previous post:

Next post: