Re: Help searching Active Directory for UserID

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



That's an active directory query?

I doubt seriously I'd search that way - that's a very inefficient query and
if you already know the mail attribute, then your query is not what you
want.
Also, keep in mind your web server needs to execute this query with
credentials sufficient to query the active directory via ldap protocol.

A query like this might be better, although you'll want to check with a
programming group more focused on adsi or vbscript.


strQuery = "<LDAP://"; & strServername &
">;(&(objectClass=person)(objectCategory=user)(mail=strEmail));sn,
department, givenname,cn,telephoneNumber,mail;subtree

<watch the wrap and such>

-ajm

"Kellie" <Kellie@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:5DDE1C39-688C-464C-BFA8-975F0C8D68C3@xxxxxxxxxxxxxxxx
I am trying to modify code that searches Active Directory by User's First
and/or Last Name. I would like to be able to search by Email address and
then display the UserName. I am having trouble with the syntax and
wondered
if anyone can help. Thanks so much!

******************
<%
'********************************************************
' function: find a user in Exchange
' author: Christian Kiefer
' email: christian.kiefer@xxxxxx
'********************************************************


'*** you only have to change this variable:
'*** the rest will work automaticly

strServerName = "xxx.xxx.xxx.xx"



'******************************************
bolSearch = false

strLastname = Request("lastname")
strName = Request("name")
strEmail =Request("mail")

'if strName<>"" or strLastname<>"" then
if strEmail<>"" then
bolSearch = true
end if

%>
<HTML>
<head>
<title>User ID Search</title>
<style>
<!--
BODY {font-family:Arial,Helvetica; font-size:10pt;}
TD {font-family:Arial,Helvetica; font-size:9pt;}
//-->
</style>
</head>
<BODY>
<CENTER><H3>User ID Search</H3><CENTER>



<%
set oConn = CreateObject("ADODB.Connection")
set oCommand = CreateObject("ADODB.Command")

oConn.Provider = "ADsDSOObject"
oConn.Open "Ads Provider"

set oCommand.ActiveConnection = oConn

if bolSearch then

'***put query string together
strQuery = "<LDAP://"; & strServername & ">;(&(objectClass=*)(sn=" &
strLastname & "*)(givenname=" & strName & "*));sn, department,
givenname,cn,telephoneNumber,mail;subtree"

oCommand.CommandText = strQuery
set oRS = oCommand.Execute

'***display table only if hits or search criteria are given
if bolSearch and not oRS.eof then
%>

<div align="center">
<table cellpadding="0" border="0" cellspacing="0">
<tr bgcolor="#C0C0C0">
<td height="20"><b>Name </b></td>
<td height="20"><b>Department </b></td>
<td height="20"><b>Telefon </b></td>
<td height="20"><b>Email </b></td>
</tr>
<%While not ors.eof%>
<tr>
<td><%=oRS.Fields("sn")%>, <%=oRS.Fields("givenname")%> </td>
<td><%=oRS.Fields("department")%> </td>
<td><%=oRS.Fields("telephoneNumber")%> </td>
<td><a
href="mailto:<%=oRS.Fields("mail")%>"><%=oRS.Fields("mail")%> </A></td>
</tr>
<%
oRS.MoveNext
wend %>
<tr bgcolor="#C0C0C0">
<td colspan="4" height="20"> </td>
</tr>
</table>
</div>
<%
else
Response.Write "No entry found"
end if

end if
%>


<br>
<br>
<form method="post" action="Search_AD.asp">
<table border="0" cellpadding="0" cellspacing="1" style="border-collapse:
collapse" bordercolor="#111111" >
<tr>
<td colspan="5" bgcolor="#C0C0C0" height="20"><b> Search</b></td>
</tr>
<tr>
<td><b>Email </b></td>
<td valign="top"><input type="text" name="email" value="<%=strEmail%>"
size="20"></td>
<!-- <td><span lang="de"><b> </b></span></td>
<td><b>N</b><span lang="de"><b>ame</b></span></td>
<td valign="top">
<p align="center">
<input type="text" name="name" value="<%=strName%>" size="20"></td> -->
</tr>
<tr>
<td> </td>
<td><input type="submit" value="Search" name="start search"></td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
</form>

</body>
</html>


.



Relevant Pages

  • Re: Search-Filter for LDAP (MS Active Directory)
    ... > a special part of Active Directory by using LDAP. ... server = 'youradserver.yourdomain.com' ... # single query; I dunno how this is changed within the query (probably ... I can get a TGT with MIT's kinit from my Active Directory server (this ...
    (comp.lang.python)
  • Re: TS on a Workgroup vs. Domain
    ... query different areas. ... > So it seems that I need to know if I'm running in a workgroup, ... I find the currently logged in user's home directory to ... >>> I query LDAP (active directory) to get the location of the user's home ...
    (microsoft.public.windows.terminal_services)
  • Re: Custom Event Sink to Query LDAP?
    ... SMTP event sinks by default run inprocess which means from a security ... running this event sink on another relay, which is what I am now doing! ... I'm trying to write a custom Event Sink in vbscript to query our Active ... the SMTP message, then look up that user in Active Directory, and pull ...
    (microsoft.public.exchange.development)
  • Re: Problem with LDAP query to resolve Email-address in C# app.
    ... Another option to consider is using the Active Directory "anr" search ... To do a search on the first name, the query would be: ... And do this search over the first childobject of the GC: ...
    (microsoft.public.exchange.applications)
  • Re: Help searching Active Directory for UserID
    ... I added displayName to the comma delimited list of ... I use line continuations to place the query on ... set oConn = CreateObject ... if bolSearch then ...
    (microsoft.public.windows.server.active_directory)