Re: Listing Group Members
- From: WianS <w.ian.stuart@xxxxxxxxxxxxxx>
- Date: Wed, 10 Dec 2008 02:52:00 -0800 (PST)
This is a script I use to enumerate the groups in my OU. You may be
able to modify it to suit your own purposes. Most of it was put
together using snippets found on the web so I don't claim it to be my
own (credit probably goes in part to some of the regulars here).
It doesn't account for nested groups as my domain is still in mixed
mode but it should be easy enough to modify if you need to enumerate
nested groups as well. To output to a text file just redirect the
output from the command console. I use tabs as seperators so that it
can be easily imported into excel if required. Other than changing the
constant for the OU you shouldn't need to modify it much to get it to
work.
Option Explicit
Dim objMemberList
Const MyOUDN = "OU=MyOU,DC=MyOrg,DC=MyCorp,DC=com"
main
'#######################################################################################
Sub main
Dim objOU
Dim objGroup, strGroup, iGroupCount
' Dictionary object to track groups.
Set objMemberList = CreateObject("Scripting.Dictionary")
objMemberList.CompareMode = vbTextCompare
' Bind to base OU.
Set objOU = GetObject("LDAP://" & MyOUDN)
' Filter on groups directly in OU.
objOU.Filter = Array("group")
' Enumerate groups.
iGroupCount = 0
For Each objGroup In objOU
iGroupCount = iGroupCount + 1
strGroup = objGroup.sAMAccountName
WScript.Echo UCASE(objGroup.sAMAccountName)
Call EnumGroup(objGroup)
Next
WScript.Echo "Total Number of Groups = " & iGroupCount
set objOU = nothing
End sub
'#######################################################################################
Sub EnumGroup(ByVal objADGroup)
Dim objMember, iCount
' Check if group already enumerated.
If (objMemberList.Exists(objADGroup.sAMAccountName) = False) Then
' Add this group to dictionary object.
objMemberList.Add objADGroup.sAMAccountName, True
iCount = 0
For Each objMember In objADGroup.Members
iCount = iCount + 1
' Check if member is a group.
If (UCase(Left(objMember.objectCategory, 8)) = "CN=GROUP") Then
' Call EnumGroup(objMember)
Else
If objMember.AccountDisabled then
wscript.Echo vbtab & objMember.sAMAccountName & vbtab &
objMember.DisplayName & vbtab & "(Account Disabled)."
Else
wscript.Echo vbtab & objMember.sAMAccountName & vbtab &
objMember.DisplayName
End if
End If
Next
If iCount = 0 Then
WScript.Echo vbtab & "Group is empty."
End if
End If
End Sub
.
- Follow-Ups:
- Re: Listing Group Members
- From: WianS
- Re: Listing Group Members
- References:
- Listing Group Members
- From: rteagardeniii
- Listing Group Members
- Prev by Date: Re: vbs to exe
- Next by Date: Re: Listing Group Members
- Previous by thread: Re: Listing Group Members
- Next by thread: Re: Listing Group Members
- Index(es):
Relevant Pages
|