Query to look up user from email address

0 views
Skip to first unread message

Chris Bordeman

unread,
Oct 29, 2009, 2:31:47 PM10/29/09
to
AD is no fun. I have LDP.exe but can't quite figure this one out.

Thanks in advance!

Chris Bordeman


Chris Bordeman

unread,
Oct 29, 2009, 4:18:22 PM10/29/09
to
BTW I know the AD query for the other way around, to get the *email* from
the *userID* is:

(&(objectClass=user)(samaccountname=chris))

Instead, I have the email address and need the real name ("Chris Bordeman")
and userID (chris).

Again thanks in advance!

"Chris Bordeman" <23...@gobleepyourselfspammers.com> wrote in message
news:e4XMUYMW...@TK2MSFTNGP02.phx.gbl...

Wayne Tilton

unread,
Oct 29, 2009, 4:45:19 PM10/29/09
to
"Chris Bordeman" <23...@gobleepyourselfspammers.com> wrote in
news:e4XMUYMW...@TK2MSFTNGP02.phx.gbl:

> AD is no fun. I have LDP.exe but can't quite figure this one out.
>
> Thanks in advance!
>
> Chris Bordeman
>

Go to www.joeware.net and download adfind.exe, then:

adfind -default -f mail=who...@wherever.com displayName

If the user might have multiple email addresses where the one you want
isn't the primary (which gets stored in 'mail'), try:

adfind -default -f proxyaddresses=smtp:who...@whereever.com

(note the 'smtp:' prefix).

HTH,

Wayne Tilton

Chris Bordeman

unread,
Oct 29, 2009, 5:03:58 PM10/29/09
to
Hi Wayne. I sort of need the actual query used because I need to do this
programatically. Know how to get that? Thanks!

"Wayne Tilton" <Wayne_...@NoSpam.Yahoo.com> wrote in message
news:Xns9CB38BED3...@207.46.248.16...

Chris Bordeman

unread,
Oct 29, 2009, 6:27:09 PM10/29/09
to
Never mind, I got it. Too simple!

"(&(objectClass=user)(mail=ch...@nowhere.com))"

"Chris Bordeman" <23...@gobleepyourselfspammers.com> wrote in message
news:emSbWtNW...@TK2MSFTNGP02.phx.gbl...

Wayne Tilton

unread,
Oct 30, 2009, 2:24:49 PM10/30/09
to
"Chris Bordeman" <23...@gobleepyourselfspammers.com> wrote in
news:OumN1bOW...@TK2MSFTNGP06.phx.gbl:

Chris,

Glad you figured that out, but the 'best' query would be:

(&(objectCategory=Person)(objectClass=User)(mail=ch...@nowhere.com))

The reason is that until Windows 2008 (or was it Exchange 2007?) the
objectClass attribute wasn't indexed, so searching by objectClass isn't
very efficient.

Wayne

Chris Bordeman

unread,
Oct 30, 2009, 2:31:30 PM10/30/09
to
Thanks very much Wayne.

"Wayne Tilton" <Wayne_...@NoSpam.Yahoo.com> wrote in message

news:Xns9CB4741B6...@207.46.248.16...

Joe Kaplan

unread,
Oct 30, 2009, 3:04:03 PM10/30/09
to
Actually, given that the mail attribute is indexed and the data is highly
unique, there is an excellent chance that you won't see any difference in
perf by doing just:
(mail=f...@bar.com)

Normally, if an index is available it will be used to locate the object and
if multiple indexes are, only the best one is selected.

If you a DA, you can use adfind or LDP with the stats option to find out!

--
Joe Kaplan-MS MVP Directory Services Programming
Co-author of "The .NET Developer's Guide to Directory Services Programming"

Reply all
Reply to author
Forward
0 new messages