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.
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.