Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Query LDAP to get user Telephone

373 views
Skip to first unread message

Omar Rodr�guez

unread,
Jun 10, 2009, 8:54:33 AM6/10/09
to
Hello,

Could you please send me a sample script, about how get the user telephone
field from active directory?

We have Windows 2003 and the users are using XP.

We need the user telefhone number from active directory in order to
configure the softphone at user logon.
Thank you in advance.

--
Greetings,
Omar Rodr�guez
Telecomunications Analyst & Programmer
VoiceTeam


Richard Mueller [MVP]

unread,
Jun 10, 2009, 9:21:53 AM6/10/09
to
Omar Rodr�guez wrote:

> Could you please send me a sample script, about how get the user telephone
> field from active directory?
>
> We have Windows 2003 and the users are using XP.
>
> We need the user telefhone number from active directory in order to
> configure the softphone at user logon.
> Thank you in advance.
>

An example to retrieve the telephone number of the current user:
=========
Set objSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)
strPhone = objUser.telephoneNumber
Call MsgBox("Your telephone number in Active Directory is " & strPhone)
======
To retrieve for another specified user, then change the number and save, the
code could be similar to:
======
' Bind to user using Distinguished Name.
Set objUser = GetObject("LDAP://cn=Jim Smith,ou=West,dc=MyDomain,dc=com")
' Retrieve telephone Number.
strPhone = objUser.telephoneNumber
' Display.
Call MsgBox("Old telephone number is " & strPhone)
' Assign a new number.
objUser.telephoneNumber = "123-456-3451"
' Save changes.
objUser.SetInfo
====
Does this help?

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


Omar Rodr�guez

unread,
Jun 10, 2009, 9:34:52 AM6/10/09
to

Thank you a lot Richard.
It works. This news group really works!

--
Greetings,
Omar Rodr�guez
Telecomunications Analyst & Programmer
VoiceTeam

"Richard Mueller [MVP]" <rlmuelle...@ameritech.nospam.net> wrote in
message news:Oo2pv5c6...@TK2MSFTNGP04.phx.gbl...

Paul Kang

unread,
Jun 12, 2009, 12:03:25 AM6/12/09
to
Hi there,

I need some help with retrieving phone number and email of a certain
user.I have written the following code that checks who has currently
opened a file on a server. Now I need to use that username which is in
the form of jsmith and use that to retrieve his full name, email and
phone number. Can this be done? jsmith is an alias in outlook. So how
do i link this to retrieve other things like full name, phone email?

Set objConnection = GetObject("WinNT://....../....")
Set colResources = objConnection.Resources

For Each objResource in colResources
If objResource.Path = "..........." Then
Document.Write("<b>Path:</b> " & objResource.Path & "<br>")
Document.Write("<b>User:</b> " & objResource.User & "<br>")
Document.Write("<br>")

Dim myUser as IADs
Set myUser = GetObject("LDAP://CN="&objResource.User&",DC=,DC=,DC=")
Document.Write("<b>Mail:</b> " & myUser.Mail & "<br>")

'Set myUser = GetObject("LDAP://CN="&objResource.User&",DC=,DC=,DC=")
with this line I am not sure if i have to put in
CN="&objResource.User&" because i want to grab details like email and
phone number. I have tried numerous different ways but have had no
luck. Could you please help and tell me where I am going wrong. How
can i link WinNT with LDAP and retrieve the details of the specified
user.

Any help or direction would be greatly appreciated.

thanks

paul


On Jun 10, 11:21 pm, "Richard Mueller [MVP]" <rlmueller-
nos...@ameritech.nospam.net> wrote:

Richard Mueller [MVP]

unread,
Jun 12, 2009, 10:50:01 AM6/12/09
to
You can use the NameTranslate object to convert between the NT format used
by the WinNT provider and the DN format used by the LDAP provider. See this
link:

http://www.rlmueller.net/NameTranslateFAQ.htm

I believe jsmith in your example is the "pre-Windows 2000 logon" name, which
is the value of the sAMAccountName attribute. If the NetBIOS name of the
domain is MyDomain, then the NT format of the name will be MyDomain\jsmith.
If you use the NameTranslate object to conver the NT name into the
Distinguished Name, you can bind with the LDAP provider and retrieve the
values of the displayName, cn, mail, and telephoneNumber attributes. The
FullName property exposed by the WinNT provider is the displayName attribute
exposed by the LDAP provider, but the cn attribute (Common Name) is often
called the full name of the user.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--

"Paul Kang" <kang...@hotmail.com> wrote in message
news:5c5b4e5c-7fec-42a4...@o5g2000prh.googlegroups.com...
Hi there,

thanks

paul

0 new messages