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

Re: How to get e-mail address attribute from AD by Torgeir

Torgeir
Wed Nov 03 13:42:57 CST 2004

Thomas Brooks wrote:

> 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?
Hi

If you are thinking about doing this for whatever user in arbitrary
containers/OUs, yes, that means some code is needed to locate the
user object in AD.


But if you want to obtain the e-mail address for current user,
things are much simpler:

'--------------------8<----------------------
Set objADSystemInfo = CreateObject("ADSystemInfo")

' Bind to the user object in AD
Set objUser = GetObject("LDAP://" & objADSystemInfo.UserName)
Wscript.Echo "SMTP Address: " & objUser.mail
'--------------------8<----------------------


--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx

Re: How to get e-mail address attribute from AD by Thomas

Thomas
Thu Nov 04 06:52:11 CST 2004

Ah, so if an administrator needs to get e-mail address for another user I
must perform all I am doing?

Thanks a lot for your help. I thought I was taking the long route. :)

"Torgeir Bakken (MVP)" <Torgeir.Bakken-spam@hydro.com> wrote in message
news:uj7J11dwEHA.1408@TK2MSFTNGP10.phx.gbl...
> Thomas Brooks wrote:
>
>> 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?
> Hi
>
> If you are thinking about doing this for whatever user in arbitrary
> containers/OUs, yes, that means some code is needed to locate the
> user object in AD.
>
>
> But if you want to obtain the e-mail address for current user,
> things are much simpler:
>
> '--------------------8<----------------------
> Set objADSystemInfo = CreateObject("ADSystemInfo")
>
> ' Bind to the user object in AD
> Set objUser = GetObject("LDAP://" & objADSystemInfo.UserName)
> Wscript.Echo "SMTP Address: " & objUser.mail
> '--------------------8<----------------------
>
>
> --
> torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
> Administration scripting examples and an ONLINE version of
> the 1328 page Scripting Guide:
> http://www.microsoft.com/technet/scriptcenter/default.mspx



Re: How to get e-mail address attribute from AD by Dave

Dave
Thu Mar 31 09:57:02 CST 2005

Can this code be run from a .asp page?

Thanks,

Dave

"Torgeir Bakken (MVP)" wrote:

> Thomas Brooks wrote:
>
> > 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?
> Hi
>
> If you are thinking about doing this for whatever user in arbitrary
> containers/OUs, yes, that means some code is needed to locate the
> user object in AD.
>
>
> But if you want to obtain the e-mail address for current user,
> things are much simpler:
>
> '--------------------8<----------------------
> Set objADSystemInfo = CreateObject("ADSystemInfo")
>
> ' Bind to the user object in AD
> Set objUser = GetObject("LDAP://" & objADSystemInfo.UserName)
> Wscript.Echo "SMTP Address: " & objUser.mail
> '--------------------8<----------------------
>
>
> --
> torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
> Administration scripting examples and an ONLINE version of
> the 1328 page Scripting Guide:
> http://www.microsoft.com/technet/scriptcenter/default.mspx
>

Re: How to get e-mail address attribute from AD by Paul

Paul
Thu Mar 31 09:57:02 CST 2005



"Torgeir Bakken (MVP)" wrote:

> Thomas Brooks wrote:
>
> > 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?
> Hi
>
> If you are thinking about doing this for whatever user in arbitrary
> containers/OUs, yes, that means some code is needed to locate the
> user object in AD.
>
>
> But if you want to obtain the e-mail address for current user,
> things are much simpler:
>
> '--------------------8<----------------------
> Set objADSystemInfo = CreateObject("ADSystemInfo")
>
> ' Bind to the user object in AD
> Set objUser = GetObject("LDAP://" & objADSystemInfo.UserName)
> Wscript.Echo "SMTP Address: " & objUser.mail
> '--------------------8<----------------------
>
>
> --
> torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
> Administration scripting examples and an ONLINE version of
> the 1328 page Scripting Guide:
> http://www.microsoft.com/technet/scriptcenter/default.mspx
>