This will dump the groups in an OU, their members, and
the count of the members. If you're only interested in a single group, you can
tweak it a bit to grab just that group.
Hunter
============================================================================
const ForReading =
1, ForWriting = 2, ForAppending = 8
Set fileSys =
CreateObject("Scripting.FileSystemObject")
Set fileTxt = fileSys.OpenTextFile("OuGroupMembers.txt", ForAppending, True)
Set fileTxt = fileSys.OpenTextFile("OuGroupMembers.txt", ForAppending, True)
set adoConnection
= CreateObject("ADODB.Connection")
adoConnection.Provider = "ADSDSOObject"
adoConnection.Open "", "", ""
adoConnection.Provider = "ADSDSOObject"
adoConnection.Open "", "", ""
set adoRecordset =
CreateObject("ADODB.Recordset")
startingOU = InputBox ("Enter the starting OU")
Set RootDSE = GetObject("LDAP://RootDSE")
searchRoot = RootDSE.Get("defaultNamingContext")
searchRoot = RootDSE.Get("defaultNamingContext")
ldapPath = "ou=" & startingOU & "," &
searchRoot
thisDate = FormatDateTime(Now(), 1)
thisDate = split(thisDate, ", ")
fileTxt.WriteLine(vbCrLf & "***********************************************************")
fileTxt.WriteLine(formatdatetime(now(),2))
fileTxt.WriteLine("")
fileTxt.WriteLine("Group Memberships in " & startingOu & " OU")
fileTxt.WriteLine("")
'Create a command object on this connection
set Com = CreateObject("ADODB.Command")
set Com.ActiveConnection = adoConnection
Com.Properties("Page Size") = 100
Com.Properties("Timeout") = 30 'seconds
Com.Properties("Searchscope") = 2 'ADS_Scope_subtree
strQuery = "<LDAP://" & ldapPath & ">;(objectClass=group);Name,ADSPath;SubTree"
com.CommandText = strQuery
Set adoRecordset = Com.Execute
Do While Not adoRecordset.EOF
i = 0
fileTxt.WriteLine("Group Name:" & VBTab & adoRecordset.Fields.Item("Name"))
fileTxt.WriteLine("Members:")
groupPath = adoRecordset.Fields.Item("ADSPath")
set objGroup = GetObject(groupPath)
set listMembers = objGroup.members
For Each member in listMembers
On Error Resume Next
fileTxt.WriteLine(VBTab & member.name & VBTab & member.sAMAccountName)
i = i + 1
Next
fileTxt.WriteLine("Total number of members in group: " & i)
adoRecordset.movenext
fileTxt.WriteLine("")
fileTxt.WriteLine("")
Loop
Wscript.Echo "Script Finished"
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Abbiss, Mark
Sent: Monday, February 07, 2005 7:40 AM
To: ActiveDir@mail.activedir.org
Subject: [ActiveDir] Obtaining a count of members in a group
Please, does anyone know of a quick way to
find the number of users in a particular security and/or distribution group in
AD and perhaps export the list ?
Many
thanks