Exchange Server Share

… Information sharing on Exchange Server …

VBScript: Write Group Membership Information to a Text File

Retrieves the membership of a specified group (including the members of any nested groups), and then writes that information to a text file. Which is not possible with normal AD tools.

Article is also available at:

=========Script Code===========

‘ ———- 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”

=========Script Code===========

Written by Amit Tank

October 30, 2007 at 1:33 pm

Posted in VBScript

%d bloggers like this: