Mark,
 
This works to return all domain global groups beginning with r*, however I'll say that if you're working with large directory spaces, it can take some time for a return.
 
Hope this helps,
Richard
 
---BEGIN CODE---

option explicit
on error resume next
 
dim RootDSE, DomainNC, DNPath, ChangeVal
dim Com, con, rs, strSearch, sDesc, strDes, i
 
Public Const ADS_SCOPE_BASE                    = 0
Public Const ADS_SCOPE_ONELEVEL                = 1
Public Const ADS_SCOPE_SUBTREE                 = 2
Public Const ADS_CHASE_REFERRALS_NEVER         = 0
Public Const ADS_CHASE_REFERRALS_SUBORDINATE   = &H20
Public Const ADS_CHASE_REFERRALS_EXTERNAL      = &H40
Public Const ADS_CHASE_REFERRALS_ALWAYS        = &H60
Public Const ADS_GROUP_TYPE_GLOBAL_GROUP       = &H2
Public Const ADS_GROUP_TYPE_DOMAIN_LOCAL_GROUP = &H4
Public Const ADS_GROUP_TYPE_UNIVERSAL_GROUP    = &H8
Public Const ADS_GROUP_TYPE_SECURITY_ENABLED   = &H80000000
 
wscript.echo "script started at: " & Now
wscript.echo ""
 
Set RootDSE = GetObject("LDAP://RootDSE")
DomainNC    = RootDSE.Get("defaultNamingContext")
 
wscript.echo "searching " & DomainNC & "..."
 
Set con = CreateObject("ADODB.Connection")
Set com = CreateObject("ADODB.Command")
 
con.Provider                       = "ADsDSOObject"
con.Properties("User ID")          = "username_here"
con.Properties("Password")         = "password_here"
con.Properties("Encrypt Password") = True
 
con.Open "Active Directory Provider"
Set Com.ActiveConnection = con
 
strSearch = "SELECT name, whenChanged, distinguishedName, memberOf " & _
   "FROM 'LDAP://" & DomainNC & "' " & _
   "WHERE objectClass='group' AND objectCategory='group' AND GroupType='" _
   & CStr(ADS_GROUP_TYPE_GLOBAL_GROUP Or ADS_GROUP_TYPE_SECURITY_ENABLED) & _
   "' AND name='r*'"
 
wscript.echo "search string: " & strSearch
wscript.echo ""
 
Com.CommandText = strSearch
 
Com.Properties("Cache Results")   = False
Com.Properties("Chase Referrals") = ADS_CHASE_REFERRALS_SUBORDINATE
Com.Properties("Page Size")       = 100
Com.Properties("searchscope")     = ADS_SCOPE_SUBTREE
Com.Properties("Sort On")         = "name"
Com.Properties("Time Limit")      = 0
Com.Properties("Timeout")         = 0
 
Set rs = Com.Execute
rs.MoveFirst
 
While Not rs.EOF
 wscript.echo " "
 wscript.echo "-----------------------------------------------------------"
 wscript.echo "name:              " & rs.Fields("name").Value
 wscript.echo "distinguised name: " & rs.Fields("distinguishedName").Value
 wscript.echo "when changed:      " & rs.Fields("whenChanged").Value
 wscript.echo "member of:         " & rs.Fields("memberOf").Value
  wscript.echo "-----------------------------------------------------------"
 rs.MoveNext
Wend
 
wscript.echo ""
wscript.echo "script ended at: " & Now
 
objFile.Close
 
---END CODE---
 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Creamer, Mark
Sent: Friday, April 30, 2004 4:31 PM
To: [EMAIL PROTECTED]
Subject: [ActiveDir] help querying for groups

Hi, can someone help me troubleshoot this script? I’m trying to return all of the global groups in the domain whose name starts with RPT. All I’m getting is the error: “Provider: Unspecified error”

 

strBase = "<LDAP://dc=my,dc=domain,dc=com>;"

strFilter = "(&(objectCategory=group)(name=RPT*));"

strScope = "Subtree"

 

Set objConn = CreateObject("ADODB.Connection")

objConn.Open "Provider=ADsDSOObject"

Set ObjRS = objConn.Execute(strBase & strFilter & strScope)

objRS.MoveFirst

While Not ObjRS.EOF

     WScript.Echo objRS.Fields(0).Value

     objRS.MoveNext

Wend

 

I’m trying to do this by altering one of the recipes in Robbie Allen’s book. Thanks!

 

Mark Creamer

Systems Engineer

Cintas Corporation

Honesty and Integrity in Everything We Do

 

Reply via email to