Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Ryan Briones

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

ADSI show ActiveDirectory distribution group members in a given OU by group

   1  
   2  On Error Resume Next
   3  
   4  strServerName = "MYDC01"
   5  strDomain = "mydomain.local"
   6  strContainer = "OU=Distribution Lists"
   7  
   8  arrDomain = Split(strDomain, ".", -1)
   9  For i = 0 to UBound(arrDomain)
  10  	arrDomain(i) = "DC=" & arrDomain(i)
  11  Next
  12  strLDAPDomain = Join(arrDomain, ",")
  13  strContainer = strContainer & "," & strLDAPDomain
  14  
  15  Wscript.StdOut.WriteLine("Group Name,Members")
  16  Set oContainer = GetObject("LDAP://" & strServerName & "/" & strContainer)
  17   
  18  For Each oChild in oContainer
  19      Wscript.StdOut.WriteLine oChild.CN & ","
  20  
  21      Set oGroup = GetObject("LDAP://" & strServerName & "/" & oChild.Name & "," & strContainer)
  22      oGroup.GetInfo
  23      arrMemberOf = oGroup.GetEx("member")
  24  	
  25      If Err.Number = 0 Then
  26      For Each strMember in arrMemberOf
  27          Set oMember = GetObject("LDAP://" & strServerName & "/" & strMember)
  28          Wscript.StdOut.WriteLine("," & oMember.CN)
  29          Set oMember = nothing
  30      Next
  31      Else
  32          Wscript.StdOut.Writeline ","
  33          Err.Clear
  34      End If
  35  	
  36      Wscript.StdOut.WriteLine ""
  37      Set oGroupList = nothing
  38  Next
  39  
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS