Re: list all groups
- From: "Richard Mueller" <rlmueller-NOSPAM@xxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 25 Oct 2006 11:58:22 -0500
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
.
- Follow-Ups:
- Re: list all groups
- From: newguy
- Re: list all groups
- Prev by Date: Re: write the no. of deleted files to a text file
- Next by Date: Re: Command from vb script fails due to command having Speech "charact
- Previous by thread: VBScript + URL Access QUestion
- Next by thread: Re: list all groups
- Index(es):
Relevant Pages
|