Re: list all groups

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



That worked great. Thanks.

"Richard Mueller" wrote:

newguy wrote:

I need to list all the groups in my AD. I know I can do that if I put in
the
ldap://ou=test,dc=test,dc=com for each ou that has a group.

I need to have this done automatically so when I or one of the other
admins
adds a group I don't want to update the script.
I would like to put in ldap://dc=test,dc=com and have it search the domain
to find all the groups. Is this possible?


You can use ADO in a VBScript program to retrieve the names of all groups in
the domain. For information on using ADO, see this link:

http://www.rlmueller.net/ADOSearchTips.htm

I modified the example in the link for your case below. I changed the filter
to filter on group objects instead of user objects. I retrieve and output
the sAMAccountName, which is the NT name (or NetBIOS name) of the groups,
plus the Distinguished Name (which reveals where each group is in the AD
hierarchy):
============
Option Explicit

Dim objCommand, objConnection, strBase, strFilter, strAttributes

Dim strQuery, objRecordset, strName, strDN



Set objCommand = CreateObject("ADODB.Command")
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
objCommand.ActiveConnection = objConnection

' Search entire domain.
strBase = "<LDAP://dc=MyDomain,dc=com>"


' Filter on group objects.
strFilter = "(objectCategory=group)"

' Comma delimited list of attribute values to retrieve.
strAttributes = "sAMAccountName,distinguishedName"

' Construct and run the query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 100
objCommand.Properties("Timeout") = 30
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute


' Enumerate the recordset.
Do Until objRecordSet.EOF
strName = objRecordSet.Fields("sAMAccountName").Value

strDN = objRecordSet.Fields("distinguishedName").value

Wscript.Echo "Name: " & strName & ", DN: " & strDN
objRecordSet.MoveNext
Loop



objRecordset.Close

objConnection.Close


--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net



.



Relevant Pages

  • Re: list all groups
    ... to filter on group objects instead of user objects. ... I retrieve and output ... Dim objCommand, objConnection, strBase, strFilter, strAttributes ... ' Filter on group objects. ...
    (microsoft.public.scripting.vbscript)
  • Re: How do I get all column descriptions from a schema.table?
    ... To avoid this issue and only retrieve the column description, we can filter ... Microsoft Online Community Support ... You can send feedback directly to my manager at: ...
    (microsoft.public.dotnet.framework.adonet)
  • Retrieve selected data from Network file
    ... I have a spreadsheet used by 100 ish people each ... The network connection ... I need to retrieve the data without opening file b. ... can filter the records using this method. ...
    (microsoft.public.excel.programming)
  • Re: track targetAddress attribute
    ... I was able to open the tool in the command prompt, ... Using the syntax from this link, the search filter would be: ... You could retrieve user names, ... count the number of users that have a value assigned to targetAddress. ...
    (microsoft.public.windows.server.active_directory)
  • Retrieve value from closed workbook without using recordsets
    ... The sheet is large and a lot of information needs to be ... The first method I used was to open the workbook, ... and took about 4 - 5 mins to retrieve the ... filter the records. ...
    (microsoft.public.excel.programming)