Apologies for the mess my code is...
I'm using code to generate an employee directory from AD. It's quite simple, but my AD has users and objects in different OU's. I want to run an if that says something like "if sn is null, loop" but I know I'm not quite putting in the syntax properly.
Should I have the sql statement filter out that info or in the code when running the loop? Current sql statement is "select givenName,sn,title,mail,telephonenumber,mobile,sAMAccountName FROM '"+ usersOU +"' where sAMAccountname='*' ORDER by sAMAccountname" I'm finding that SN and title are the empty AD attributes.
<h1>Company Directory</h1>
<%
' Define the AD OU that contains our users
usersOU = "LDAP://OU=xxx,DC=xxx,DC=com"
' Make AD connection and run query
Set objCon = Server.CreateObject("ADODB.Connection")
objCon.provider ="ADsDSOObject"
objCon.Properties("User ID") = "xxx"
objCon.Properties("Password") = "xxx"
objCon.Properties("Encrypt Password") = TRUE
objCon.open "Active Directory Provider"
Set objCom = CreateObject("ADODB.Command")
Set objCom.ActiveConnection = objCon
objCom.CommandText ="select givenName,sn,title,mail,telephonenumber,mobile,sAMAccountName FROM '"+ usersOU +"' where sAMAccountname='*' ORDER by sAMAccountname"
Set objRS = objCom.Execute
' Loop over returned recordset and output HTML
Response.Write "<table border=1>" + vbCrLf
Do While Not objRS.EOF Or objRS.BOF
Response.Write " <tr>"
Response.Write "<td>" + objRS("givenName") + " "
+ objRS("sn") + "<br>" + objRS("title") + "<br>"
+ objRS("sAMAccountName") + "</td>"
Response.Write "<td>" + objRS("mail") + "<br>"
Response.Write + objRS("telephonenumber") + "
<br>"
Response.Write + objRS("mobile") + "</td>"
Response.Write "</tr>" + vbCrLf
objRS.MoveNext
Response.Flush
Loop
Response.Write "</table>"
' Clean up
objRS.Close
objCon.Close
Set objRS = Nothing
Set objCon = Nothing
Set objCom = Nothing
%>
I want a list of only humans with name, title, email, phone number, mobile number. I don't want any DL's or computers from AD.
Aucun commentaire:
Enregistrer un commentaire