For the VBS posted earlier, listMembers is supposed to be
an array, so if you want to get the number of members you can output a
ubound(listMembers) -
lbound(listMembers).
To batch adfind the following should
work:
for /f "tokens=1*" %i in (groups.txt) do
(
adfind adfind -b dc=domain,dc=com -f samaccountname=%%i
member |grep -c ">member"
)
Where
groups.txt is a file containing all samaccountnames of the
groups.
Another example which should work:
dsget
group "CN=groupname, OU=GroupsOU, DC=domain, DC=com" -members | find /c /i
"dc="
If you
want all groups you can go with
dsquery group domainroot -name * | dsget group -members | find /c /i
"dc="
DISCLAIMER: Examples not tested, but should work (at least slightly
modified). I'm to lazy to fire up a DC to test right now
;-)
Gruesse -
Sincerely,
Ulf B. Simon-Weidner
MVP-Book "Windows XP - Die Expertentipps": http://tinyurl.com/44zcz
WebSite: http://www.windowsserverfaq.org
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of joe
Sent: Monday, February 07, 2005 5:07 PM
To: ActiveDir@mail.activedir.org
Subject: RE: [ActiveDir] Obtaining a count of members in a groupI'm so proud, it brings a tear to my eye. :o)Also for the first questionadfind -b dc=domain,dc=com -f samaccountname=groupname member |grep -c ">member"Doing this for multiple groups is trickier. No doubt it can be done with batch commands but I'm not the one that could do it.joe
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Coleman, Hunter
Sent: Monday, February 07, 2005 10:58 AM
To: ActiveDir@mail.activedir.org
Subject: RE: [ActiveDir] Obtaining a count of members in a groupIn that case, you could use adfind like this:adfind -b dc=subdomain,dc=domain,dc=com -f "(&(objectcategory=person)(memberOf=cn=Group1,ou=Test1,dc=subdomain,dc=domain,dc=com)(memberOf=cn=Group2,ou=Test3,dc=subdomain,dc=domain,dc=com)" name <any other attributes you want returned>
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Abbiss, Mark
Sent: Monday, February 07, 2005 8:19 AM
To: ActiveDir@mail.activedir.org
Subject: RE: [ActiveDir] Obtaining a count of members in a groupMany thanks, excellent help.I hope I am not pushing my luck by asking for another brainstorm on how I can do a simple check for how many members are found both in GROUP1 and GROUP2. These are quite large groups (>1000 members) and I cannot do it by visual checkingThanks again.-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Coleman, Hunter
Sent: Montag, 7. Februar 2005 15:58
To: ActiveDir@mail.activedir.org
Subject: RE: [ActiveDir] Obtaining a count of members in a groupThis 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 = 8Set fileSys = CreateObject("Scripting.FileSystemObject")
Set fileTxt = fileSys.OpenTextFile("OuGroupMembers.txt", ForAppending, True)set adoConnection = CreateObject("ADODB.Connection")
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")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 = strQuerySet 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("")
LoopWscript.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 groupPlease, 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