Find the Display Name from email address from Active Directory

As a Exchange Administrator, I supposed know the answer for the following question in a blink of an eye. 

Where are the mails go when I send to this email address?

Well, that’s what I thought. It’s a more general email address like I searched for Distribution list or a mailbox or even a contact object. None. Best thing about "Active Directory Users and Computers" is you can NOT search by a email address.

My instinct says it must be a "Mail Enabled" Public Folder. So I searched through the public folders hierarchy.  There is lots of them and none of them has the specified email address attached. Exchange System Manager blankly said it delivered locally to the server.

I decided to use my special skill called "Scripting". I wrote the following script to get the display name of the email address from the Active Directory. Voila!!! I found what I was looking for in seconds.

Below is that script. If you want to use it, change the "Domain Name" for DomainContainer variable.

‘*********                       GetDisplayName.vbs                 **********
‘********* Parameters: email address                                **********
‘*********                                                          **********
‘********* This script queries the Active Directory by Email        **********
‘********* Address and displays the "Display Name" of the object.   **********

‘*********                                                          **********
‘********* Usage: GetDisplayName.vbs           **********
‘*********                                                          **********
‘********* Written By: Anand Venkatachalapathy                      **********

Set rootDSE=GetObject("LDAP://RootDSE")
DomainContainer = rootDSE.Get("defaultNamingContext")

Set conn = CreateObject("ADODB.Connection")
conn.Provider = "ADSDSOObject"
conn.Open "ADs Provider"

sMail =  "SMTP:" & WScript.Arguments(0)  
DomainContainer = "DC=company,DC=com"
ldapStrUsers = "<LDAP://" & DomainContainer & _
">;(&(&(& (proxyAddresses=" & sMail & _
") (| (&(objectCategory=*)(objectClass=*)) ))));adspath;subtree"

Set rs1 = conn.Execute(ldapStrUsers)

While Not rs1.EOF
      Set FoundObject = GetObject (rs1.Fields(0).Value)
      WScript.Echo FoundObject.CN

Set rs1=Nothing
Set conn = Nothing
Set rootDSE = Nothing


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s