Home All Groups Group Topic Archive Search About

Enumerating computer list from certain OU's in AD



Author
10 May 2005 7:51 PM
masao112
I would like to filter my computer list to 2 or more OU's rather than the
entire domain. Here's my code so far:

<head>
<body>
<table width="100%" bordercolor="blue" cellspacing="0">
<tr>
<td bgcolor="blue"><font color="white" face="arial" size="3"><b>Development
and Quality Assurance</b></font></td>
</tr>
<tr>
<td bgcolor="blue">
</td>
</tr>
</table>
<form action="FindComputerName.asp" method="get">
    <b>Computer Name:</b> <input type="text" name="computername"><br>
    <input type="submit" value="Find"> <br>
</form>

<%
Dim sComputerName
sComputerName=Request.QueryString("computername")

If sComputerName <> "" Then
    GetComputerName
End If


Sub GetComputerName

'Option Explicit
On Error Resume Next

Dim sAttributes
Dim sBase
Dim oCommand
Dim oConnection
Dim sDomain
Dim sFilter
Dim oRecordset
Dim sResult
Dim oRootDSE
Dim sScope
Dim sSort
Set oConnection = Server.CreateObject("ADODB.Connection")
Set oCommand = Server.CreateObject("ADODB.Command")
Set oRootDSE = GetObject("LDAP://RootDSE")
sDomain = oRootDSE.Get("DefaultNamingContext")
sBase =  "<LDAP://" & sDomain & ">;"
sFilter = "(&(objectCategory=Computer)(Name=" & sComputerName & "*));"
sAttributes = "Name,ADsPath,operatingSystem,whenCreated;"
sScope = "SubTree "
sSort = "Name"


oConnection.Provider = "ADsDSOObject"
oConnection.Open "Active Directory Provider", "vc_ho\WbemScriptUser"
,"ConnectServer!"
oCommand.ActiveConnection = oConnection
oCommand.Properties("Sort On") = sSort
oCommand.Properties("Page Size") = 1000
oCommand.CommandText = sBase & sFilter & sAttributes & sScope

Set oRecordset = oCommand.Execute
If oRecordset.Recordcount = 0 Then
    Response.Write ("No objects found")
Else
    Response.Write("<table border=""1"" bordercolor=""gray"" cellspacing=""0"">")
    Response.Write("<tr>")
    Response.Write("<td bgcolor =""blue""><Font Color = ""white"" Face =
""Arial""><b>Computer Name</b></td>")
    Response.Write("<td bgcolor =""blue""><Font Color = ""white"" Face =
""Arial""><b>ADS Path</b></td>")
    Response.Write("<td bgcolor =""blue""><Font Color = ""white"" Face =
""Arial""><b>OS</b></td>")
    Response.Write("<td bgcolor =""blue""><Font Color = ""white"" Face =
""Arial""><b>Created</b></td>")
    Response.Write("</tr>")
    oRecordset.MoveFirst
    Do Until oRecordset.EOF
        Response.Write("<td><font face=""arial"" size=""2""> " &
oRecordset.Fields("Name").value & "</td>")
        Response.Write("<td><font face=""arial"" size=""2""> " &
oRecordset.Fields("ADsPath").value & "</td>")
        Response.Write("<td><font face=""arial"" size=""2""> " &
oRecordset.Fields("operatingSystem").value & "</td>")
        Response.Write("<td><font face=""arial"" size=""2""> " &
oRecordset.Fields("whenCreated").value & "</td>")
        Response.Write("</tr>")
        oRecordset.MoveNext
    Loop
    Response.Write("</table>")
End If

oRecordset.Close
oConnection.Close   

Set oCommand = Nothing
Set oConnection = Nothing
Set oRecordset = Nothing
Set oRootDSE = Nothing
End Sub

%>
<style>
    body
        {font:10pt Tahoma;
        font-weight:normal;
        color:black;}
    h1
        {font:18pt Tahoma;
        font-weight:bold;
        color:#13215D;}
    h2
        {font:10pt Tahoma;
        font-weight:bold;
        color:blue;}
    h3
        {font:18pt Tahoma;
        font-weight:bold;
        color:black;}
    th
        {font:8pt Tahoma;
        font-weight:bold;
        color:white;
        background-color:blue;
        padding-left:5px;
        padding-right:5px;}
    td
        {font:8pt Tahoma;
        padding-left:5px;
        padding-right:5px;}

</style>
</body>
</html>

AddThis Social Bookmark Button