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

On Error Resume Next

strServerName = "MYDC01"
strDomain = "mydomain.local"
strContainer = "OU=Distribution Lists"

arrDomain = Split(strDomain, ".", -1)
For i = 0 to UBound(arrDomain)
	arrDomain(i) = "DC=" & arrDomain(i)
Next
strLDAPDomain = Join(arrDomain, ",")
strContainer = strContainer & "," & strLDAPDomain

Wscript.StdOut.WriteLine("Group Name,Members")
Set oContainer = GetObject("LDAP://" & strServerName & "/" & strContainer)
 
For Each oChild in oContainer
    Wscript.StdOut.WriteLine oChild.CN & ","

    Set oGroup = GetObject("LDAP://" & strServerName & "/" & oChild.Name & "," & strContainer)
    oGroup.GetInfo
    arrMemberOf = oGroup.GetEx("member")
	
    If Err.Number = 0 Then
    For Each strMember in arrMemberOf
        Set oMember = GetObject("LDAP://" & strServerName & "/" & strMember)
        Wscript.StdOut.WriteLine("," & oMember.CN)
        Set oMember = nothing
    Next
    Else
        Wscript.StdOut.Writeline ","
        Err.Clear
    End If
	
    Wscript.StdOut.WriteLine ""
    Set oGroupList = nothing
Next

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