Recursive LDAP function to get nested groups (roles) and users

Also Check Out: My latest venture. – a way for you to ask questions and get answers about local businesses around you. iTunes link: (only available in US for now)

Here is a simple recursive function that I wrote which will give you nested groups and members for any given Active Directory group. Try it….it works! U can bind it to a tree later on to show it on the screen. I have also included an output of how it looks when bound to an iewc Treeview.


Dim AdsPath as string
Dim XMLRoles as string

AdsPath = GetAdsPathOfGroupThroughADO(“Domain Admins”)
XMLRoles = GetRoleMembers(Adspath)


Public Function GetAdsPathOfGroupThroughADO(ByVal Group As String) As String
On Error Resume Next
Set rs = CreateObject(“ADODB.RecordSet”)
rs.Open “;(sAMAccountName=” & Group & “);adspath”, “provider=ADsDSOObject”

If Not rs.EOF Then
s = rs(0).Value
End If

GetAdsPathOfGroupThroughADO = s
End Function
Public Function GetRoleMembers(ByVal RoleAdsPath As String) As String
Dim eu As Object
Dim XML As String

Set eu = CreateObject(“ess.user”)
Set Group = GetObject(RoleAdsPath)
XML = “”

For Each member In Group.Members
If member.Class = “Group” Then
XML = XML & vbCrLf & GetRoleMembers(member.ADsPath)
ElseIf member.Class = “foreignSecurityPrincipal” Then
On Error Resume Next
Set u = GetObject(“LDAP://=” & eu.SidStringToHexString( & “>”)
If Err.Number = 0 Then
XML = XML & vbCrLf & “”
End If
End If

XML = XML & vbCrLf & “”
GetRoleMembers = XML
End Function


eg. TreeView1.TreeNodeSrc = “XML returned by GetRoleMembers()….”
TreeView1.TreeNodeXsltSrc = Server.MapPath(“Treetransform.xslt”)


3 thoughts on “Recursive LDAP function to get nested groups (roles) and users

  1. So rather than walking at a constant speed for say an hour, you’ll modify points up by alternating short bursts of extreme strolling for say a minute followed by a recovery period with slower strolling following just about every intense period. Just keep alternating for twenty minutes to start and add time while you become extra fit. You’ll be
    able to use interval education with all phases in theprocera avh
    to boost your success.

    Also whenever you do any form of workout it truly is strongly suggested you drink plenty
    of water prior to throughout and right after to maintain
    your entire body appropriately hydrated.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s