Using vbscript, what is a simpliar to retrieve the value for the e-mail
address attribute for an AD user?
The following will get the desired value, but I am curious as to why I have
to do so much to get the value. I guess my main question is why do I have
to perform the steps below the nametranslate comment and then having to
convert results? Is there no simpliar way to get e-mail address for a
username? If so would someone post the code?
Thank you.
Code snippet:
strNTName = "xusername"
' Determine DNS domain name from RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("rootDomainNamingContext")
wscript.echo strdnsdomain
' Use NameTranslate to find the NetBIOS domain name
' from the DNS domain name.
Set objTrans = CreateObject("NameTranslate")
objTrans.Init 3, strDNSDomain
objTrans.Set 1, strDNSDomain
strNetBIOSDomain = objTrans.Get(3)
wscript.echo strnetbiosdomain
' Use NameTranslate to convert the NT user name to the
' Distinguished Name required for the LDAP provider.
objTrans.Init 1, Left(strNetBIOSDomain, _
Len(strNetBIOSDomain) - 1)
objTrans.Set 3, strNetBIOSDomain & strNTName
strUserDN = objTrans.Get(1)
wscript.echo struserdn
' Bind to the user object in AD
Set objUser = GetObject("LDAP://" & strUserDN)
Wscript.Echo "SMTP Address: " & objUser.mail