Today’s script is made for Tyrone.
His question was a script that enumerates all groups and their members from a given OU.
I already had a script that enumerates the members of an OU.
I also had a script that enumerates the members of a nested group (uses recursion).
The 2 scripts combined are the solution for Tyrone.
Follow the next steps to run the script (no admin rights needed):
* open your favorite text editor
* copy and paste the script into the editor
* change the OU distinguished name (in line 7) into your OU distinguished name
* save the script (for example c:\temp\EnumerateGroupsInOu.vbs)
* open a command prompt
* go to “c:\temp”
* give “cscript EnumerateGroupsInOu.vbs” (without quotes) and enter
You can also dump the output to a file:
* give “cscript EnumerateGroupsInOu.vbs > EnumerateGroupsInOu.txt” (without quotes) and enter
To get that file into Excel:
* open Excel
* go to Menu=>Open File
* change file type to “all”
* chose EnumerateGroupsInOu.txt
* chose “;” as separator character
The script:
' Name : EnumerateGroupsInOu.vbs
' Description : script to enumerate all groups and their members from a specific Active Directory OU
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 01-06-2011
Set objOU = GetObject("LDAP://OU=test,DC=test,DC=org")
For Each objMember in objOU
If (LCase(objMember.Class) = "group") Then
EnumNestedgroup objMember.AdsPath
End If
Next
Set objOU = Nothing
Function EnumNestedgroup(strGroupDN)
Set objGroup = GetObject(strGroupDN)
For Each objMember in objGroup.Members
If (LCase(objMember.Class) = "group") Then
wscript.echo objMember.AdsPath
EnumNestedgroup objMember.AdsPath
Else
Wscript.Echo objGroup.Name & " ; " & objMember.DisplayName & " ; " & objMember.Mail &_
" ; " & objMember.Department & " ; " & objMember.Company & " ; " & objMember.Title
End If
Next
Set objGroup = Nothing
End Function
When you have problems/questions with the script please post a reply.
Happy scripting.
Best regards,
Dirk Adamsky
