Title: Message
I'm so proud, it brings a tear to my eye. :o)
 
Also for the first question
 
adfind -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 group

In 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 group

Many 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 checking
 
Thanks 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 group

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 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 = 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

Reply via email to