[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

List of email addresses including all aliases in Active Directory

Posted on 2009-02-19
5
Medium Priority
?
5,966 Views
Last Modified: 2012-05-06
Hey there!

I have found a nice vb script that will extract the email addresses for my active directory users.

However I need to extract ALL addresses, including aliases.

I'm trying to clean up my spam filter system that was not properly configured, and I need to delete about 500 users from it, and it would be handy to have a all-inclusive list of all email addresses and aliases to work from.  This is going to take a long time as it is, and without a list to work from it will take too long.

Attached is the script that will produce a list of the main email addresses for the users, and it works great, but it is not exactly what I need.  This script is already posted, but I am including it here for the people that find this post in a search engine, who's needs are met by this script.


Thanks!
George
'===========================================
'* Enter the DN of the container you want to base your 
'* search in, excluding the domain name (dc=domain,dc=com),
'* between the double quotes below. If you want it to
'* search the root leave it blank.
 
strContainer = "" 
 
 
strDirectory = "c:\work"
strFile = "UserEmailAddr.txt"
strOutput = strDirectory & strFile
 
 
'------ Check or Create csv file -------
 
' Create the File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
' Check that the strDirectory folder exists
If objFSO.FolderExists(strDirectory) Then
   Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFolder = objFSO.CreateFolder(strDirectory)
WScript.Echo "Just created " & strDirectory
End If
 
If objFSO.FileExists(strDirectory & strFile) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFile = objFSO.CreateTextFile(strDirectory & strFile)
Wscript.Echo "Just created " & strDirectory & strFile
End If 
 
set objFolder = nothing
set objFile = nothing
 
If err.number = vbEmpty then
Set objShell = CreateObject("WScript.Shell")
objShell.run ("Explorer" & " " & strDirectory)
Else WScript.echo "VBScript Error: " & err.number
End If
 
 
'---------- Write to file -----------
 
Set objRootDSE = GetObject("LDAP://rootDSE")
 
If strContainer = "" Then
    strADsPath = objRootDSE.Get("defaultNamingContext")
Else
    strADsPath = strContainer & "," & objRootDSE.Get("defaultNamingContext")
End If
 
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
 
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
 
 
'--- change the DN to where you want to start your search ---
objCommand.CommandText = _
    "<LDAP://" & strADsPath & ">;" & _
        "(objectCategory=User)" & _
        ";distinguishedName,name,mail;subtree"
 
Set objRecordSet = objCommand.Execute
set fso = createobject("scripting.filesystemobject")
 
Set objFile = FSO.OpenTextFile(strOutput, 8) 
objFile.WriteLine "Username" & vbTab & "Email Address" & vbTab & "Distinguished Name"
objFile.Close
 
While Not objRecordSet.EOF
 
    Set objFile = FSO.OpenTextFile(strOutput, 8) 
    objFile.WriteLine objRecordSet.Fields("Name") & vbTab & _
                      objRecordSet.Fields("Mail") & vbTab & _
                      objRecordSet.Fields("distinguishedName")
    objFile.Close
    objRecordSet.MoveNext
 
Wend
 
objConnection.Close
'===============================================

Open in new window

0
Comment
Question by:georgew3
5 Comments
 
LVL 57

Accepted Solution

by:
Mike Kline earned 300 total points
ID: 23685152
one of the VBscript guys will help with that but can I suggest another method.  That is using Joe Richards adfind tool
http://www.joeware.net/freetools/tools/adfind/index.htm
adfind -b DC=yourdomain,DC=com(or whatever your suffix is)  -f  "&(objectcategory=person)(objectclass=user)"  samaccountname mail mailnickname proxyaddresses -csv >  c:\usersemail.csv
That will spit out those attributes into a csv file for you.
mailnickname is the alias.
Please let me know how that works for you.
Thanks
Mike
0
 
LVL 6

Assisted Solution

by:Jammer59
Jammer59 earned 150 total points
ID: 23685176
This script loops through all the proxy email addresses.  Hope it helps.
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_23272381.html
0
 
LVL 8

Assisted Solution

by:JustWorking
JustWorking earned 150 total points
ID: 23685727
0
 
LVL 71

Assisted Solution

by:Chris Dent
Chris Dent earned 75 total points
ID: 23690261

George,

Can you export a list of addresses from the spam filter? It would be easy enough to verify those with what you have in Active Directory, would potentially save a lot of time (rather than comparing static lists).

Chris
0
 
LVL 23

Assisted Solution

by:Jeremy Weisinger
Jeremy Weisinger earned 75 total points
ID: 23696248
Hi George,

I like Mike's suggestion of using adfind.

I would use this string instead as it will filter out the x400 addresses and it will also get any mail enabled object:
adfind.exe -sc exchaddresses:smtp -csv > allemail.csv

Mike, I think he means "proxy addresses" when he says aliases
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Active Directory can easily get cluttered with unused service, user and computer accounts. In this article, I will show you the way I like to implement ADCleanup..
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question