'//////////////////////////////////////////////////////////////////////////
'/// Name: ListADGroups.vbs
'/// Version: 1.0
'/// Date: 09/17/02
'/// Purpose: listing information about Active Directory groups
'/// OS: Windows 2000, XP
'/// Reqs: Account with permissions to read Active Directory groups properties
'/// Syntax: cscript /nologo ListADGroups.vbs
'//////////////////////////////////////////////////////////////////////////
Option Explicit
On Error Resume Next
'////////////////////////////////////////////////////
'/// Variable Declarations
Dim oRootDSE, oCon, oCmd, oRecordSet
Dim sDomainADsPath, sUser, sPassword, sGroup, sProperties
Dim aDescription, aMember, iCount
'////////////////////////////////////////////////////
'/// Extract domain name of the logged on user account
Set oRootDSE = GetObject("LDAP://RootDSE")
sDomainADsPath = "LDAP://" & oRootDSE.Get("defaultNamingContext")
Set oRootDSE = Nothing
'////////////////////////////////////////////////////
'/// Create, configure, and open ADO Connection object
Set oCon = CreateObject("ADODB.Connection")
oCon.Provider = "ADsDSOObject"
sUser = "UserName"
sPassword = "Password"
oCon.Open "ADProvider", sUser, sPassword
'////////////////////////////////////////////////////
'/// Create and configure ADO Command object
Set oCmd = CreateObject("ADODB.Command")
Set oCmd.ActiveConnection = oCon
sProperties = "name,ADsPath,description,member"
sGroup = "*"
oCmd.CommandText = "<" & sDomainADsPath & ">;(&(objectCategory=group)(name=" & sGroup & "));" & sProperties & ";subtree"
oCmd.Properties("Page Size") = 100
'////////////////////////////////////////////////////
'/// Populate ADO RecordSet object with AD Group info
Set oRecordSet = oCmd.Execute
'////////////////////////////////////////////////////
'/// Display results by listing all records in Recordset
WScript.Echo "Global Groups for the domain " & Replace(Mid(sDomainADsPath,11), ",DC=", ".")
While Not oRecordSet.EOF
WScript.Echo "Name: " & vbTab & oRecordSet.Fields("name")
WScript.Echo "ADsPath: " & vbTab & oRecordSet.Fields("ADsPath")
aDescription = oRecordSet.Fields("description")
If Not IsNull(aDescription) Then
WScript.Echo "Description: " & vbTab & aDescription(0)
End If
aMember = oRecordSet.Fields("member")
WScript.Echo "Members: "
If Not IsNull(aMember) Then
For icount = 0 to UBound(aMember)
WScript.Echo vbTab & vbTab & aMember(iCount)
Next
End If
oRecordSet.MoveNext
Wend
'////////////////////////////////////////////////////
'/// Close Recordset and Connection objects
oRecordSet.Close
oCon.Close
'////////////////////////////////////////////////////
'/// Clean up
Set oRecordSet = Nothing
Set oCon = Nothing