Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email From AD 1

Status
Not open for further replies.

notrut

Programmer
Feb 6, 2002
87
CA
Hi,

I know almost nothing about AD, but I need to retrieve an users email address from it. I would like to use the following vbs script:

on error resume next
Set objuser = GetObject("WinNT://TEST/someonesID,email")
strEmail = objuser.EmailAddress
wscript.echo "someonesID Email Address is " & strEmail

Is this possible??? or is there some version of this script that would work??

Any help would be greatly appreciated.

Thanks in advance.
 
This script can be used to get properties from AD. This works to get properties of Joseph Poandl


On Error Resume Next
Set objUser = GetObject _
("LDAP://cn=joseph poandl,ou=users,ou=US,dc=us,dc=domain,dc=com")
objUser.GetInfo

strGivenName = objUser.Get("givenName")
strInitials = objUser.Get("initials")
strSn = objUser.Get("sn")
strDisplayName = objUser.Get("displayName")
strPhysicalDeliveryOfficeName = _
objUser.Get("physicalDeliveryOfficeName")
strTelephoneNumber = objUser.Get("telephoneNumber")
strMail = objUser.Get("mail")
str = objUser.Get("
strDescription = objUser.GetEx("description")
strOtherTelephone = objUser.GetEx("otherTelephone")
strUrl = objUser.GetEx("url")

WScript.echo "givenName: " & strGivenName
WScript.echo "initials: " & strInitials
WScript.echo "sn: " & strSn
WScript.echo "displayName: " & strDisplayName
WScript.echo "physicalDeliveryOfficeName: " & _
strPhysicalDeliveryOfficeName
WScript.echo "telephoneNumber: " & strTelephoneNumber
WScript.echo "mail: " & strMail
WScript.echo " " & str
For Each strValue in strDescription
WScript.echo "description: " & strValue
Next
For Each strValue in strOtherTelephone
WScript.echo "otherTelephone: " & strValue
Next
For Each strValue in strUrl
WScript.echo "url: " & strValue
Next



If you just want email address:

On Error Resume Next
Set objUser = GetObject _
("LDAP://cn=joseph poandl,ou=users,ou=US,dc=us,dc=domain,dc=com")
objUser.GetInfo

strMail = objUser.Get("mail")
WScript.echo "mail: " & strMail



-later


Joseph L. Poandl
MCSE 2003

If your company is in need of experts to examine technical problems/solutions, please check out (Sales@njcomputernetworks.com)
 
Thanks for the reply, but I have a couple of more questions:

in your script:

On Error Resume Next
Set objUser = GetObject _
("LDAP://cn=joseph poandl,ou=users,ou=US,dc=us,dc=domain,dc=com")
objUser.GetInfo
strMail = objUser.Get("mail")
WScript.echo "mail: " & strMail

there are 3 dc='s and 2 ou='s. Is this correct??

Also, what does the ou= mean??
 
notrut,

In that section you have highlighted you need to set the information for the user you are looking for.

cn is the context name (Username)
ou is the name of the OU the user is in
If you are using nested OU's then you need the second OU=
DC= is your domain

So for example if your username was "notrut", you were in the "Desktop Users" OU, and your domain was "mydomain.domainname.com"

then that LDAP line would read:
("LDAP://cn=notrut,ou=Desktop Users,dc=mydomain,dc=domainname,dc=com")

and one more example:
if your username was "notrut", you were in the "Desktop Users" OU which was UNDER the "West Coast" OU, and your domain was "mydomain.domainname.com"

then that LDAP line would read:
("LDAP://cn=notrut,ou=Desktop Users,ou=West Coast,dc=mydomain,dc=domainname,dc=com")

I hope that give you a little beter understanding. For any more explanation I would do a google search for LDAP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top