[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 9036
  • Last Modified:

get emailaddress of user in Active directory using ldap query

Currently I have LDAP query

(&(objectCategory=contact)(objectCategory=person)(mail=*)(objectClass=user)) which is returning the user name .I want only thr email address of the user in return
0
sourabh1
Asked:
sourabh1
  • 3
  • 3
  • 2
  • +4
5 Solutions
 
Chris DentPowerShell DeveloperCommented:

LDAP queries define which objects should be returned, they don't define which properties should be returned and displayed.

How are you using the filter above at the moment? That's where we need to define what you see.

Chris
0
 
sourabh1Author Commented:
In my case i need to pass the username  and in return i need its email address
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Chris DentPowerShell DeveloperCommented:

What are you using to do this?

Chris
0
 
pubeheedCommented:
I woud suggest using powershell for this you can download the quest AD cmdlets using the link below and they work on 2003 as well as 2008 DCs. You shoud install them on your machine rather than the DC.
http://www.quest.com/powershell/activeroles-server.aspx 

you would use the command below to find this for just one user
get-qaduser Samaccountname | select samaccountname,mail

or is you want all enabled users accountname and email use this:

get-qaduser -ldapfilter "(mail=*)" -enabled | select samaccountname,mail | export-csv c:\temp\userlist.csv

0
 
Farhan KaziSystems EngineerCommented:
If you are apply this query using ADUC snap-in -> Saved Queries then make sure you have selected "E-Mail Address" from add / remove columns.
Right click on Query that have you made -> View -> Add/Remove Columns -> E-Mail Address

Alternatively you can perform this from command line:
Click Start -> Run -> Cmd.exe -> OK

DSQuery * -Filter "(&(objectCategory=contact)(objectCategory=person)(mail=*) (objectClass=user))" -Attr samAccountName Mail -Limit 0

Hope this helps!
Farhan


0
 
PorpathamCommented:
Dear Friend,
You can follow any one of them. Please check and reply.

1, dsquery user -name "user name"|dsget user -samid -email -display

2, Ok - perhaps I wasn't clear - but you're close enough - what I guess I wanted was: dsquery user -samid "loginname" |dsget user -email
0
 
sourabh1Author Commented:
Yes Porpatahm u r right
0
 
sourabh1Author Commented:
I want  that LDAP query which will take loginname and return me the emailid.
No dotnet code for this
0
 
Shreedhar EtteCommented:
Hi,

In your query put mail=*$EmailAddress*

and check.

I hope this helps,
Shree
0
 
PorpathamCommented:
Dear Friends,

              Please mention did the Comment Helpful?

Then only i will know the progress..................

Please..................................
0
 
mrfixit584Commented:
Try this.. It will return the username and email address. If the email address isn't there it will only return the username.

'on error resume next
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"

Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 30000

objCommand.CommandText = _
 "<LDAP://dc=company,dc=com>;" & _
 "(&(objectCategory=person)(objectClass=user));" & _
 "cn, mail;subtree"

Set objRecordSet = objCommand.Execute
'wscript.echo objRecordset.RecordCount
If objRecordSet.RecordCount > 0 Then
objRecordSet.MoveFirst


 While Not objRecordset.EOF
strUser = objRecordset.Fields("cn")
strMail = objRecordset.Fields("mail")
if strMail <> "" then
wscript.echo strUser & "," & strMail
Else
wscript.echo strUser & ","
End if

 objRecordset.MoveNext
 Wend

End If

objConnection.Close
0
 
mrfixit584Commented:
The script I provided above will provide the info needed.
0
 
Chris DentPowerShell DeveloperCommented:

I recommend Split between these:

http:#29771789 (shreedhar)
http:#29774205 (pubeheed)
http:#29777319 (farhankazi)
http:#29782221 (Porpatham)
http:#30030433 (mrfixit584)

All of the methods provided are viable.

Chris
0

Featured Post

Easily manage email signatures in Office 365

Managing email signatures in Office 365 can be a challenging task if you don't have the right tool. CodeTwo Email Signatures for Office 365 will help you implement a unified email signature look, no matter what email client is used by users. Test it for free!

  • 3
  • 3
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now