Title: Message
This is pretty simple adsi vbscript I use when I get those kind of "who is in that group" question.
It prompts for the NetBIOS domain name, group name, & file to save as (in CSV style output)
 
Clyde Burns
 
----------------------------

' Gets input on the domain name, group name, and file name
' Then outputs the NT login ID and the Users full name
' to the specified file name in a csv style format.
 

Do
   strDomain = inputbox( "Enter the netbios domain name.", "Input" )
Loop until strDomain <> ""
 
Do
   strGroup = inputbox( "Enter the name of the group you want to check (for instance:
 
Domain Admins).", "Input" )
Loop until strGroup <> ""
 
Do
   strFile = inputbox( "Please enter the name of the file you want to save this as. (for
 
instance: C:\list.csv).", "Input" )
Loop until strFile <> ""
 
Set objGroup = GetObject("WinNT://" & strDomain & "/" & strGroup & ",group")
 
Dim fso, textfile
Set fso = CreateObject("Scripting.FileSystemObject")
Set textfile = fso.CreateTextfile(strFile, True)
 
textfile.Writeline ("Membership list of " & chr(39) & strGroup & chr(39))
textfile.WriteBlankLines(1)
textfile.Writeline (chr(34) & "NT Login ID" & chr(34) & chr(44) & chr(34) & "Full Name" &
 
chr(34))
 

For Each objUser In objGroup.Members
textfile.Writeline (chr(34) & objUser.Name & chr(34) & chr(44) & chr(34) &
 
objuser.FullName & chr(34))
x=x+1
Next
   
textfile.writeline vbcrlf & "Total Number: " & x
textfile.close
 
WScript.Echo strfile & " has been generated."
 
 

 

From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of joe
Sent: Monday, February 07, 2005 11:07 AM
To: ActiveDir@mail.activedir.org
Subject: RE: [ActiveDir] Obtaining a count of members in a group

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

This message is confidential, intended only for the named recipient(s) and may contain information that is privileged or exempt from disclosure under applicable law. Any patient health information must be delivered immediately to intended recipient(s). If you are not the intended recipient(s), you are notified that the dissemination, distribution or copying of this message is strictly prohibited. If you receive this message in error, or are not the named recipient(s), please notify the sender at either the e-mail address or telephone number above and discard this e-mail. Thank you.

Reply via email to