从AD中提取代码的信息会在多个不同的OU中引入用户和对象,以及如何过滤掉对象

时间:2019-04-22 23:05:32

标签: sql if-statement select active-directory

很抱歉我的代码是...

我正在使用代码从AD生成员工目录。这很简单,但是我的AD在不同的OU中具有用户和对象。我想运行一个if语句,例如“ if sn为null,循环”,但我知道我不太正确地输入语法。

运行循环时,是否应让sql语句过滤掉该信息或代码中的信息?当前的SQL语句是“选择给定的名称,sn,标题,邮件,电话号码,移动电话,sAMAccountName FROM'“ + usersOU +”'其中sAMAccountname ='*'按sAMAccountname进行排序”我发现SN和标题是空的AD属性。

    <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
        %>

我只想列出一个人的名字,标题,电子邮件,电话号码,手机号码。我不需要AD的任何DL或计算机。

0 个答案:

没有答案