'Get the recursive groups from the active user
Set oAD = CreateObject("ADSystemInfo")
Set GroupsOfUser = GetMembership(oAD.UserName, null)
MsgBox Join(GroupsOfUser.Items(), "," & vbCrLf)
'Get the recursive groups from a specific group
Set GroupsOfGroup = GetMembership("CN=SomeGroup,OU=MyGroupContainer,DC=MyDomain,DC=local", null)
MsgBox Join(GroupsOfGroup.Items(), "," & vbCrLf)
Function GetMembership(sChild, dMembership)
'Get AD info on the given Child
Set oChild = GetObject("LDAP://" & sChild)
If TypeName(oChild) = "Object" Then
'Add the Child's canonical name to the array IF it's a group
If TypeName(dMembership) = "Dictionary" Then
dMembership.Add oChild.distinguishedName, oChild.CN
Else
Set dMembership = CreateObject("Scripting.Dictionary")
End If
'If the Child has any parents (=groups), run the same loop for these parents.
If TypeName(oChild.memberOf) = "Variant()" Then
oParents = oChild.GetEx("memberOf")
For Each sParent in oParents
If Not dMembership.Exists(sParent) Then
Set dMembership = GetMembership(sParent, dMembership)
End If
Next
End If
End If
Set GetMembership = dMembership
End Function