Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

General LDAP question - Structure

Status
Not open for further replies.

Staticfactory

IS-IT--Management
Mar 1, 2005
79
CA
I'm just getting my feet wet with VBscript in an attempt to turn tedious/repetitive jobs into scripts. We're about to do some security restructuring in Active Directory and have about 150 different user groups that I would like to generate member reports for. I've been looking at some primers for the coding methods for this, but I'm still hung up on the whole CN/OU/DC structuring of the LDAP string. Of course, I'm not overly thorough in the idea of AD yet either, so please bear with me.

I was hoping someone could clear this up for me using the following example.

Domain is ad.mydomain.net

Under the domain, in the AD console I have NTAM - Toronto - MyCompany - Groups/Users/Computers.

Now, I'm trying to query the groups for it's members but am not sure how to structure the CN/OU/DC elements of the LDAP string to get at them.

I hope this makes a shred of sense!
 
Statictactory,

Here you go:
There is nothing proprietary in this script. It should run as is. You will need to run it under the context of a domain user. You can not run this with anonymous access enabled in IIS. Let me know if you have any questions.

Code:
<%@ Language=VBScript %>
<%
response.buffer = true
SUB CloseAll
   rs.close
   set rs=nothing
   con.close
   set con=nothing
END SUB
%>
<html>
<head>
<script language=JScript runat=server>
    function SortVBArray(arrVBArray) {
        return arrVBArray.toArray().sort().join('\b');
    }
</script>
</head>
<body>
<%
groupdsn=request.querystring("group")
if groupdsn="" then
 Set objDomain = GetObject ("GC://rootDSE")
 objADsPath = objDomain.Get("defaultNamingContext")
 Set objDomain = Nothing
 Set con = Server.CreateObject("ADODB.Connection")
 con.provider ="ADsDSOObject"
 con.open "Active Directory Provider"
 Set Com = CreateObject("ADODB.Command")
 Set Com.ActiveConnection = con
 Com.CommandText ="select adspath,name from 'GC://"+objADsPath+"' WHERE objectCategory='Group' ORDER BY name"
 Set rs = Com.Execute
 if rs.EOF then
  Call CloseAll
  response.write "No Groups Found."
  else
   rsarray=rs.getrows
   Call CloseAll
   numrows=ubound(rsarray,2)
   for rowcounter=0 to numrows
    response.write "<a href='"+Request.ServerVariables("SCRIPT_NAME")+"?group="+rsarray(1,rowcounter)+"'>"+rsarray(0,rowcounter)+"</a><br>"
   next
 end if
 else
  set objgroup=GetObject(groupdsn)
  response.write "<b>Members of "+groupdsn+"</b><br>"
  tempstr=""
  For each objMember in objGroup.Members
   if tempstr<>"" then
    tempstr=tempstr&"#"
   end if
   tempstr=tempstr&objMember.CN
  next
  Set objGroup=nothing
  temparray=split(tempstr,"#")
  SortArray = Split(SortVBArray(temparray), Chr(8))
  For iLoop = LBound(SortArray) to UBound(SortArray)
   response.write SortArray(iLoop)+"<br>"
  next
end if
%>
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top