Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

list of email addresses 2

Status
Not open for further replies.

UKHicks

IS-IT--Management
May 11, 2004
141
US
How can i export a list of all email addresses within our organization? Is there a search option i'm missing somewhere?

We are running Exchange 2003 SP1 on Windows 2003 Server SP1
 
here you go. Save this script to a text file. Give it a name of EnumSMTP.VBS and double click it ot make a report of addresses. The report is comma seperated so you can easily import into Excel if you wish.

Code:
'==========================================================================
'
' NAME: EnumSMTP.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.TheSpidersParlor.com[/URL]
' COPYRIGHT (c) 2005 All Rights Reserved
' DATE  : 7/28/2004
'
' COMMENT: 
'
'==========================================================================

vbComma = chr(44)
Set Root = GetObject("LDAP://RootDSE")
DNC = "LDAP://" & Root.Get("DefaultNamingContext")

Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
"Select mail, cn, ProxyAddresses from '" & DNC & "' " _
& "where mail='*@*' ORDER BY cn"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30 
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
objCommand.Properties("Cache Results") = False
report = report & "Name" & vbcomma & "SMTP" & vbCrLf
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
i = 0
Do Until objRecordSet.EOF
strName = objRecordSet.Fields("cn")
Set regEx = New RegExp ' Create regular expression.
Set regEx1 = New RegExp ' Create regular expression.
regEx.Pattern = "^smtp:" ' Set pattern.
regEx1.Pattern = "^SMTP:SystemMailbox{" ' Set pattern.
regEx.IgnoreCase = True ' Set case sensitivity.
regEx1.IgnoreCase = True ' Set case sensitivity.
'go through each of the elements in ProxyAddresses only keep those that start with smpt:
arrProxylist = objRecordSet.Fields("ProxyAddresses").Value
For each Addy in arrProxylist
	retVal = regEx.Test(Addy) ' Execute the search for smtp:.
	If retVal Then
		retVal1 = regEx1.Test(Addy) ' Execute the search for SystemMailbox.
		If NOT retVal1 Then
			i = i + 1 
			report = report & strName & vbComma & "     " & Addy & vbCrLf
		End IF
	End If
Next
objRecordSet.MoveNext
Loop

Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.CreateTextFile ("EnumeratedSMTPAddresses.txt", ForWriting)
ts.write report
wscript.echo "Report Created"
set ts = nothing


I hope you find this post helpful.

Regards,

Mark
 
So do i need a copy of visual basic installed?

If i double click it, it just opens the text file
 
did you name it as specified? If you did, go to tools options and unhide the file extensions.
 
heheh, good call. that was dumb of me
 
Yup, When all else fails...read the directions. :)

I hope you find this post helpful.

Regards,

Mark
 
markdmac,

Is there a way to get rid of the addrss@companyname.local addresses from the exported text file when generated?

Thanks
 
Yes, here is a version that can do that.

Code:
'==========================================================================
'
' NAME: EnumSMTPNoLocal.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.TheSpidersParlor.com[/URL]
' COPYRIGHT (c) 2005 All Rights Reserved
' DATE  : 9/22/2005
'
' COMMENT: 
'
'==========================================================================

vbComma = chr(44)
Set Root = GetObject("LDAP://RootDSE")
DNC = "LDAP://" & Root.Get("DefaultNamingContext")

Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
"Select mail, cn, ProxyAddresses from '" & DNC & "' " _
& "where mail='*@*' ORDER BY cn"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30 
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
objCommand.Properties("Cache Results") = False
report = report & "Name" & vbcomma & "SMTP" & vbCrLf
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
i = 0
Do Until objRecordSet.EOF
strName = objRecordSet.Fields("cn")
Set regEx = New RegExp ' Create regular expression.
Set regEx1 = New RegExp ' Create regular expression.
Set regEx2 = New RegExp ' Create regular expression.
regEx.Pattern = "^smtp:" ' Set pattern.
regEx1.Pattern = "^SMTP:SystemMailbox{" ' Set pattern.
regEx2.Pattern = ".local" ' Set pattern.
regEx.IgnoreCase = True ' Set case sensitivity.
regEx1.IgnoreCase = True ' Set case sensitivity.
regEx2.IgnoreCase = True ' Set case sensitivity.

'go through each of the elements in ProxyAddresses only keep those that start with smpt:

arrProxylist = objRecordSet.Fields("ProxyAddresses").Value
For each Addy in arrProxylist
	retVal = regEx.Test(Addy) ' Execute the search for smtp:
	If retVal Then
		retVal1 = regEx1.Test(Addy) ' Execute the search for System mailboxes.
		If NOT retVal1 Then
   		retVal2 = regEx2.Test(Addy) ' Execute the search for local addresses.
			If NOT retVal2 Then
			i = i + 1 
			report = report & strName & vbComma & "     " & Addy & vbCrLf
			End If
		End IF
	End If
Next
objRecordSet.MoveNext
Loop

Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.CreateTextFile ("EnumeratedSMTPAddresses.txt", ForWriting)
ts.write report
wscript.echo "Report Created"
set ts = nothing

I hope you find this post helpful.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top