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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adsi/ldap and asp 1

Status
Not open for further replies.

mlowe9

Programmer
Apr 3, 2002
221
0
0
US
I've almost given up on this. I want to be able to access some different AD fields using ASP. (We've only been on AD for a couple of months now). I can use:

Code:
set cont = GetObject("WinNT://apollo")
for each obj in cont
  response.write obj.name & "-" & obj.fullName & "<BR>"
next

and this will give a list of all users and their "Full Name", which I think equates to Description. But from what I've found, I need to use LDAP get get more specific, and it also looks like I need the OU of the user to do that. Is that true? How do I know the user's ou ahead of time? Can anyone help me understand this and make it work the way I want?
 
Ok, I found this:
Code:
set oADSobj = getobject("LDAP://cn=username,cn=Users,dc=myserver,dc=mydomain,dc=org")
response.write oADSobj.get("homephone")
and that gets me the home phone of the user. BUT, I still have to know the part of AD the user is in (Users in this case), and if the home phone number field doesn't have a value, I get an error. THAT SUCKS.

Any hints on this?
 
Ok, now I'm on FIRE!!!

Code:
set objADSysInfo = createobject("ADSystemInfo")
strUser = objADSysInfo.Username
set objUser = getobject("LDAP://" & strUser)
response.write objUser.cn & "<BR>"
response.write objUser.Firstname & "<BR>"
response.write objUser.LastName & "<BR>"
response.write objUser.HomePhone & "<BR>"
response.write objUser.Description & "<BR>"

This looks like what I'm wanting. I don't have to specify an OU, but I still get an error if the field is not valued. Can I code around that (without Resume next)? Also, where can I get a list of the fields, like .cn, .FirstName, .LastName, etc.?
 
Something like the following:
Code:
Dim conn, rs, strSql, strConn

Set conn = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")

conn.Provider = "ADsDSOObject"
strConn = "Active Directory Provider"

conn.Open strConn

strSql = "SELECT givenname, sn FROM 'LDAP://yourdomain' WHERE objectclass = 'user'"

rs.Open strSql, conn

Response.Write rs.RecordCount

The above is going to query AD for every object that is classified as a User. You can whittle it down even more by providing other criteria just as you would for a general SQL statement. A good place to find a lising of all of the fields in AD is [link]www.Kouti.com/tables/userattributes.htm[/url]
 
I will definitely try that. Didn't know I could pull the stuff into a recordset. Thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top