Solved

Map Active Directory Logon Account to email address.

Posted on 2013-11-04
7
692 Views
Last Modified: 2013-11-06
Map AD Logon Account to email address.

we have Active directory Logon account as numbers. but email addresses are First initial and last name.

example: our AD domain is = Mydomain.Corp
my logon account  is=111111
and my email address is = john@Mydomain.com

as you notice the AD domain name is different than email domain name.

I have a list of users AD accounts:
111111
222222
333333
444444
555555

I want to send them emails through a script , but I do not know how to map their AD account to their email address through a Script..

Any help will be very much appreciated.

Thank you.
0
Comment
Question by:jskfan
7 Comments
 
LVL 25

Assisted Solution

by:Diverse IT
Diverse IT earned 100 total points
ID: 39623529
Hi jskfan,

Can I ask why you have it setup like that?

What version of Exchange are you running?
0
 
LVL 21

Expert Comment

by:dan_blagut
ID: 39623675
Hi
Is the email address field of AD account OK?

Dan
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 400 total points
ID: 39623895
Hi, see if this script will work to give you the "mail" property of each user account in your input file.

Regards,

Rob.

strInputFile = "Users.txt"
strOutputfile = "Results.csv"

If Right(LCase(WScript.FullName), 11) = "wscript.exe" Then
	Set objShell = CreateObject("WScript.Shell")
	objShell.Run "cscript """ & WScript.ScriptFullName & """", 1, False
	Set objShell = Nothing
	WScript.Quit
End If

Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1

Set objInputFile = objFSO.OpenTextFile(strInputFile, intForReading, False)

Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection

 ' Search entire Active Directory domain.
Set objRootDSE = GetObject("LDAP://RootDSE")

strDNSDomain = objRootDSE.Get("defaultNamingContext")
strBase = "<LDAP://" & strDNSDomain & ">"

strDetails = """Login Name"",""Email"""

While Not objInputFile.AtEndOfStream
	strNumber = objInputFile.ReadLine
	WScript.Echo "Looking for " & strNumber
	
	strFilter = "(&(objectCategory=person)(objectClass=user)(samAccountName=" & strNumber & "))"
	
	' Comma delimited list of attribute values to retrieve.
	strAttributes = "samAccountName,mail"
	
	' Construct the LDAP syntax query.
	strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
	adoCommand.CommandText = strQuery
	adoCommand.Properties("Page Size") = 100
	adoCommand.Properties("Timeout") = 30
	adoCommand.Properties("Cache Results") = False
	
	' Run the query.
	Set adoRecordset = adoCommand.Execute
	 
	' Enumerate the resulting recordset.
	Do Until adoRecordset.EOF
	    ' Retrieve values and display.
		strUserName = adoRecordset.Fields("samAccountName").Value
		strMail = adoRecordset.Fields("mail").Value
		strDetails = strDetails & VbCrLf & """" & strUserName & """,""" & strMail & """"
	    ' Move to the next record in the recordset.
	    adoRecordset.MoveNext
	Loop
	
	' Clean up.
	adoRecordset.Close
	Set adoRecordset = Nothing
Wend

adoConnection.Close

Set objOutputFile = objFSO.CreateTextFile(strOutputFile, True)
objOutputFile.Write strDetails
objOutputFile.Close
Set objOutputFile = Nothing

WScript.Echo "Done"
MsgBox "Done. Please see " & strOutputFile

Open in new window

0
 
LVL 37

Expert Comment

by:Jamie McKillop
ID: 39624172
What version of Exchange?

-JJ
0
 

Author Closing Comment

by:jskfan
ID: 39628583
Thanks
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MaxPosPhaseCorrection setting 3 21
Active Directory Photo Tab 4 25
Active Directory Forest 5 32
Exchange 2010 Send Connector 6 9
In this step by step procedure, you will come to know the details of creating an Outlook meeting in 2007, 2010, 2013 & 2016.
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

773 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