Submitted By: Amit Tank

Retrieves the membership of a specified group (including the members of any nested groups), and then writes that information to a text file.

Visual Basic
' --------------------- Determine variable ---------------------------------------
Dim outfile

'------------------------Create File System Object Space --------------------------
Set fso = CreateObject("Scripting.FileSystemObject")

' ------------------------- Define variable for Output file to write -----------------------------
set outfile = fso.createtextfile("Members.txt",true)

on error resume next
'-------------Call the Function for Finding Group Membership - including nested groups---------------

strGroupDN = "CN=Domain Admins,CN=Users,DC=Domain,DC=com" 

'*****Give here DN of Group*****'

strSpaces  = " "
set dicSeenGroupMember = CreateObject("Scripting.Dictionary")
outfile.writeline "Members of " & strGroupDN & ":"DisplayMembers "LDAP://" & strGroupDN, strSpaces, dicSeenGroupMember

Function DisplayMembers ( strGroupADsPath, strSpaces, dicSeenGroupMember)
   set objGroup = GetObject(strGroupADsPath)
   for each objMember In objGroup.Members
      outfile.writeline strSpaces &
      if objMember.Class = "group" then
         if dicSeenGroupMember.Exists(objMember.ADsPath) then
            outfile.writeline strSpaces & "   ^ already seen group member " & "(stopping to avoid loop)"
            dicSeenGroupMember.Add objMember.ADsPath, 1
            DisplayMembers objMember.ADsPath, strSpaces & " ", dicSeenGroupMember
         end if
      end if
End Function

MsgBox "Group Membership has been dumped to -Members.txt- file"