Enumerate members of nested groups

I have the following script courtesy of Experts Exchange whcih works a treat.  I am looking for it to do exactly the same but also export nested users and groups into the output file...any suggestions? Thanks

'Script begins here
Dim objGroup, objUser, objFSO, objFile, strDomain, strGroup, Domain, Group
'Change DomainName to the name of the domain the group is in
strDomain = Inputbox ("Enter the Domain name", "Data needed", "Default domain name")
'Change GroupName to the name of the group whose members you want to export
strGroup = InputBox ("Enter the Group name", "Data needed", "Default group name")
Set objFSO = CreateObject("Scripting.FileSystemObject")
'On the next line change the name and path of the file that export data will be written to.
Set objFile = objFSO.CreateTextFile("C:\" & strGroup & " - Members.txt")
Set objGroup = GetObject("WinNT://" & strDomain & "/" & strGroup & ",group")
For Each objUser In objGroup.Members
    objFile.WriteLine objUser.Name & " - " & objUser.Class
Set objFile = Nothing
Set objFSO = Nothing
Set objUser = Nothing
Set objGroup = Nothing
Wscript.Echo "Done"
Wscript.Echo "Please check the c: for your output file"
Who is Participating?
Hi, you can't do this with the WinNT provider.  You need to use LDAP.

Here's a quick example.


EnumMembers "CN=YourGroup,OU=TestUsers,DC=Domain,DC=Com"
Wscript.Echo "Done."

Sub EnumMembers(strDN)
	Set objGroup = GetObject("LDAP://" & strDN)
	WScript.Echo "Enumerating group " & Mid(objGroup.Name, 4)
	For Each objUser In objGroup.Members
	    If objUser.Class = "user" Then WScript.Echo Mid(objUser.Name, 4)
	For Each objUser In objGroup.Members
	    If objUser.Class = "group" Then EnumMembers objUser.distinguishedName
End Sub

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.