|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Need help using ASP/ADO/ADSI to pull information from Active Directory
I know there are probably several dozen resources on this but I haven't been able to find anything simple I could just follow or copy.
I'd like to use ASP (preferably just regular ASP, not .NET) to pull out a few properties of each user object in one Organization Unit of my active directory (and the sub-OUs below it)... that's it.... I just want to be able to get about 7 pieces of information. I don't need to edit active directory or anything like that. I understand you can pull information using ADO/ADSI interface, but I can't figure out how to do it. All the examples I've found seem to be for WScript instead of ASP. The ones I do find for ASP seem to be missing important things, like they assume I should have already done something or had some other code. If someone could just give me a semi complete sample code that pulls this information and writes it out, I do know enough ASP that I can make adjustments as needed to format it the way I want. I really just want to be able to copy some code that works and then make the adjustments from there. I can pay someone for this code if that'll get me a response... can't pay much, but it would be worth it. Just reply here to let me know. Here is some information about my domain/site (if you need more to help me, just let me know). domain = stjosephsvilla.net domain controller = sjv-domain-2 ou = Staff Accounts properties I want to retrieve (from user objects only) -name -title -department -mobile -pager -telephoneNumber Last edited by olandir : March 31st, 2006 at 01:51 PM. Reason: Trying to get responses |
|
#2
|
|||
|
|||
|
Actually something fairly decent on microsoft for this
I found two articles from the Scripting Guys on Microsoft's Tales from the Script.
The articles Are: Dude, Where's My Printer: Using Scripts to Search Active Directory (Part 1) Dude, Where's My Printer: Using Scripts to Search Active Directory (Part 2 of 2) It is vbscript, which is bascially asp, so just enclose the code withing <%...%>. It requires, of course, that you replace your LDAP string (i.e. CN, DC, etc.). It is a good start. |
|
#3
|
|||
|
|||
|
Wscript and ASP ARE NOT THE SAME
Quote:
I put this code in a .vbs file and ran it, and it works PERFECTLY Code:
On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
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
objCommandProperties("Sort On") = "Name"
objCommand.CommandText = _
"SELECT Name FROM 'LDAP://ou=Servers,dc=stjosephsvilla,dc=net' WHERE objectCategory='user'"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Wscript.Echo objRecordSet.Fields("Name").Value
objRecordSet.MoveNext
Loop
However, I put this code in an ASP page and tried to open the page and I get NOTHING but a blank page. It idles for like 2 minutes, then I get nothing. Then I get no response from Internet Explorer. Obviously ASP and Wscript are different... I was clever enough to change Wscript.echo to Response.write, but that must not be the only difference. Code:
On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
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
objCommandProperties("Sort On") = "Name"
objCommand.CommandText = _
"SELECT Name FROM 'LDAP://ou=Servers,dc=stjosephsvilla,dc=net' WHERE objectCategory='user'"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Response.write objRecordSet.Fields("Name").Value
objRecordSet.MoveNext
Loop
|
|
#4
|
|||
|
|||
|
This is what I use - in ASP on IIS 6
Hi there,
If you haven't has an answer yet, try this. It works for me... Code:
Sub GetUsers
dim con,com, domainPath, rs
Set con = CreateObject("ADODB.Connection")
Set com = CreateObject("ADODB.Command")
domainPath = "LDAP://mydomain.com"
'Open the ADSI Connection.
con.Provider = "ADsDSOObject"
'Credentials
con.Properties("User ID") = "Username"
con.Properties("Password") = "Password"
con.Open "Active Directory Provider"
Set Com.ActiveConnection = con
Com.CommandText = "<" & domainPath & ">;(&(objectCategory=person)(objectClass=user));ADsPath ,name,telephoneNumber,title,physicalDeliveryOffice Name,department,objectCategory,objectClass;subtree "
Com.Properties("Page Size") = 64
Com.Properties("Timeout") = 30 'seconds
Com.Properties("Cache Results") = False
Set rs = Com.Execute
Response.Write "<Table>"
do until rs.eof
Response.Write "<TR>"
Response.Write "<TD>" & rs("Name").value & "</TD>"
Response.Write "<TD>" & rs("title").value & "</TD>"
Response.Write "<TD>" & rs("telephoneNumber").value & "</TD>"
Response.Write "<TD>" & rs("department").value & "</TD>"
Response.Write "</TR>"
rs.movenext
loop
Response.Write "</Table">
con.Close
set rs = nothing
set com = nothing
set con = nothing
end sub
For a list of all the properties you can select, try http://www.rlmueller.net/References/ADUCProperties.xls cheers Dominic |
![]() |
| Viewing: ASP Free Forums > Other > Programming Help > Need help using ASP/ADO/ADSI to pull information from Active Directory |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|