View Full Version : Query AD with ASP
nolascof
07-09-2002, 06:46 PM
Hi. I'm stuck in with a scripting problem so maybe someone can help.
I created a script file (.wsf) that allows me to query AD for a given user and find the all the groups the user is a member of, using the memberOf property. The script works fine on its own, but is limited. Therefore, I tried creating an ASP form that will allow me to enter a valid user ID and query from that point on using the same mechanics as I had in the script file. However, whenever I submit the form, I recieve the following message:
The Active Directory datatype cannot be converted to/from a native DS datatype
Any ideas?
darkness
07-09-2002, 07:18 PM
Can you post or email me your scripts I ran into that error before but I can't remember what I did to fix it.
Michael McLaughlin/images/forums/icons/smile.gif
Systems Manager
Minnesota State University Mankato
nolascof
07-09-2002, 08:08 PM
strUserRDN = "cn=" & strCloneID
' Connect to the Provider, ADSDSSOObject
Set adoConnection = CreateObject ("ADODB.Connection")
adoConnection.Provider = "ADSDSOObject"
adoConnection.Open "", vbNullString, vbNullString
If adoConnection.State <> adStateOpen Then
Response.Write "Internal Error"
End If
' Construct the filter
strFilter = "(&(objectClass=User)(" & strUserRDN & "))"
strBase = "<LDAP://dc=asbhost>"
' Execute the query and record the resulting AdsPath
Set adoRecordset = adoConnection.Execute (strBase & ";" & strFilter & ";AdsPath;SubTree")
If adoRecordset.EOF Then
Response.Write "The Username provided could not be located in Active Directory."
End If
strADsPath = adoRecordset.Fields.Item("ADsPath").Value ' LDAP://CN=username,OU=department,DC=asbhost
Response.Write strADsPath & "
"
adoConnection.Close
Set adoRecordset = Nothing
'************************************************* ********************
'*
'* Purpose: Find all groups the user is a member of then separate
'* those that belong to an application group and a drive
'* mapping group.
'* Input: None.
'*
'************************************************* ********************
Set adsObject = GetObject (strADsPath) ' Based on the user's ADsPath
adsProp = "memberOf"
adsObject.GetInfoEx Array("memberOf"), 0
adsObject.GetInfo
Dim strTemp
strTemp = adsObject.Get("memberOf")
Response.Write strTemp
Set oRegExp_App = New RegExp
oRegExp_App.Pattern = "OU=Applications"
oRegExp_App.IgnoreCase = True
Set oRegExp_Att = New RegExp
oRegExp_Att.Pattern = "OU=Drive_Mappings"
oRegExp_Att.IgnoreCase = True
' For Each memberOfElement In adsObject.GetEx(adsProp) ' 'memberOfElement' is the DN of all the group the user is a member of
' If (oRegExp_App.Test (memberOfElement)) Then ' Separates those groups that belong to the Application OU
' arrDNofApps = Split (memberOfElement, ",")
' strResults = strResults & Mid(arrDNofApps(0), 4) & VbCrLf
' ElseIf (oRegExp_Att.Test (memberOfElement)) Then ' Separates those groups that belong to the Drive Mappings OU
' arrDNofDriveMappings = Split (memberOfElement, ",")
' strResults = strResults & Mid(arrDNofDriveMappings(0), 4) & VbCrLf
' End If
' Next
Set adsObject = Nothing
Set oRegExp_App = Nothing
Set oRegExp_Att = Nothing
Response.Write strResults & "
"
Powered by vBulletin™ Version 4.1.0 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.