Google

Tuesday, October 30, 2007

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:
http://www.microsoft.com/technet/scriptcenter/csc/scripts/ad/groups/cscad109.mspx

=========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 & objMember.name
if objMember.Class = "group" then
if dicSeenGroupMember.Exists(objMember.ADsPath) then
outfile.writeline strSpaces & " ^ already seen group member " & "(stopping to avoid loop)"
else
dicSeenGroupMember.Add objMember.ADsPath, 1
DisplayMembers objMember.ADsPath, strSpaces & " ", dicSeenGroupMember
end if
end if
next
End Function
MsgBox "Group Membership has been dumped to -Members.txt- file"

=========Script Code===========
Google Groups
Subscribe to IT_Discussions
Email:
Visit this group