Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get AD group type

Status
Not open for further replies.

cluM09

Technical User
May 15, 2004
127
US
Hello,

I am trying to get the group type from AD with the following function, but the script generates an error and cannot get the group type.

Private Function getGroupType(ByVal strGroupName)
Dim objRootDSE, strDomainDN, objConnection
Dim objCommand, objRecordSet
Const ADS_SCOPE_SUBTREE = 2
Const ADS_GROUP_TYPE_SECURITY_ENABLED = &h80000000
Set objRootDSE = GetObject("LDAP://RootDSE")
strDomainDN = objRootDSE.Get("defaultNamingContext")
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = "SELECT grouptype " & _
"FROM 'LDAP://" & strDomainDN & "' WHERE " & _
"objectCategory='group' AND Name='" & strGroupName & "'"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
If objRecordSet.Fields("grouptype").Value And _
ADS_GROUP_TYPE_SECURITY_ENABLED Then
getGroupType = "Security"
Else
getGroupType = "Distribution"
End If
objRecordSet.MoveNext
Loop
objConnection.Close
Set objRootDSE = Nothing: Set objCommand = Nothing
Set objRecordSet = Nothing
End Function

Any idea what I did wrong?

Thanks.

 
the script generates an error
Any chance you could post the error message and which line of code raises it ? (I guess the MoveFirst call)
Anyway your function will return nothing...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top