Solved

Map Active Directory Logon Account to email address.

Posted on 2013-11-04
7
688 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 24

Assisted Solution

by:diverseit
diverseit 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

Utilizing an array to gracefully append to a list of EmailAddresses
Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…
how to add IIS SMTP to handle application/Scanner relays into office 365.

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now