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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

export all email addresses from AD

Status
Not open for further replies.

tamaro

IS-IT--Management
Apr 8, 2003
37
0
0
US
Hello, I'm looking for a script too look at AD and export all email addresses to a csv file that it has just the name, email address. the problem i have is that each user has more than one smpt address and i also need the distribution lists i have searched for hours and cant find one please help!
 
for some reason your link does not work, and yes Hours. i'm not good at VBS so it is hard, all i found would not give you all email addresses it gives you just one.
 
I have a script that will output to a text file. It wouldn't be too difficult to modify this to a CSV file. The strLDAP line and the line below should be on the same line.
Code:
Const ForReading = 1
Const ADS_SCOPE_SUBTREE = 2
Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile ("c:\users6.txt", ForReading)
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
'Create output file
Set fs = CreateObject ("Scripting.FileSystemObject")
filePath = "c:\forJenn.txt"
Set outFile = fs.CreateTextFile (filePath)
outFile.Close
Set rootDSE = GetObject("LDAP://RootDSE")
DomainContainer = rootDSE.Get("defaultNamingContext")
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
i = 0
Do Until objTextFile.AtEndOfStream
    strNextLine = objTextFile.Readline
    objDictionary.Add i, strNextLine
    i = i + 1
Loop

For Each objItem in objDictionary
    strUser = objDictionary.Item(objItem)
    Wscript.Echo strUser
    strLDAP = "<LDAP://" & DomainContainer & ">;(&(mailNickname=" & strUser & ")(objectCategory=person)(objectClass=user));adspath;subtree"
objCommand.CommandText = strLDAP
Set rs = objCommand.Execute
Set ts = fs.OpenTextFile(filePath,8)
While Not rs.EOF
	Set FoundObject = GetObject (rs.Fields(0).Value)
	arrProxyAddresses = FoundObject.proxyAddresses
	For Each Address In arrProxyAddresses
			strMessage=(FoundObject.Displayname & vbTab & Address)
			ts.WriteLine strMessage
	Next
	ts.WriteLine " "
    rs.MoveNext
Wend
ts.Close
Next
MsgBox "Script has completed..."
WScript.Quit
 
For CSV change this line:

strMessage=(FoundObject.Displayname & vbTab & Address)

to

strMessage=(FoundObject.Displayname & "," & Address)

I hope this is what you're looking for.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top