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

ADSI Help

Status
Not open for further replies.

rbri

Programmer
Jun 27, 2002
84
0
0
US
Hello Everyone

My saga continues with the Active Directory. With help from earlier postings and experimentation of code I am able to accomplish what I want but it is terribly slow. Should I be searching the Active Directory differently than just cycling through the Active Directory with this code.

'-------------------------------------------
Dim strDomin, strLine, objProvNt
strDomain = "(myDomain)"
Set objProvNt = GetObject("WinNt://" & strDomain)
objProvNt.Filter = Array("User")
For Each strLine In objProvNt
MsgBox strLine
Next

'--------------------------------------------

In the completed program I prompt the user for a name to search for so other than the code used to manipluate the name field the above code is what is used to perform the search on the Active Directory. Posed with the original question are 2 more parts that are related. 1) Is there a way to search a specific OU within my domain. An example of this is here are only two examples out of a page fill of OU's (usmiflt) and (usmikok) both of these OU's reside in my domain.
2) After I get the results from my search the name field
example of this field is (Lastname, FirstName MiddleIntil)
is there away to get the users username, our username is totally different from our full name. Here is an exapmle (gzw9ty) is the user name (Doe, John R) is the full name there are no parenthesis.
 
I'm just getting into VBS and ADSI myself, but I've got a couple of observations/hints for you.

1) I don't think you're really accessing Active Directory with the code above. You're talking to your Domain Controller with the GetObject("WinNt://" & strDomain). AD is an LDAP provider and your Getobject should look something like this:
GetObject("LDAP://OU=Users,DC=mydomain,DC=com")

2) Since AD is an LDAP provider, then SQL queries should help you search & filter. I think we used ADO to query AD (LDAP) on a page so that we could pull out the user's first name and provide a greeting like "Hello, Bob!" when we only had the userid. This sounds very similar to what you're trying to do. Now if I could only find that code.... I'll be back!
 
Thanks

That code really helped. I still have a problem through,
all the code or examples I seem to find make the assuption that I already know the users username which in my case has know remote relationship/common look to there real name. So do you know the field names that I can search on that I can supply their first or last name to return their username? In general I know everyones real first name or last name but do not know their username. The only code example I could find to do this was the code I used, where I use GetObject("WinNt://" & strDomain) which is very slow is there something simular in GetObject("LDAP://" & (search domain and OU)

Thanks for your help.
 
Depending on where you put the info in AD would depend on where it is (sometimes), but generally:

givenName = First Name
initials = Middle Initial
sn = Last Name (or surname, thus the sn)

This snippet from the sample I referenced above is the key to your request to use the real name to find the userid (samAccountName).

objCommand.CommandText = &quot;<LDAP://dc=fabrikam,dc=com>;(&(objectCategory=User)&quot; & &quot;(samAccountName=&quot; & strUserName & &quot;));samAccountName;subtree&quot;

It's seaching the objectCategory=User for a samAccountName=strUserName and then return the samAccountName. If I wanted to find a Surname in AD and get back the Surname, First Name and SAM Account Name it would probably go like this (don't know for sure, I didn't test it):

objCommand.CommandText = &quot;<LDAP://dc=fabrikam,dc=com>;(&(objectCategory=User)&quot; & &quot;(sn=&quot; & strLastName & &quot;));sn, givenName, samAccountName;subtree&quot;

The MS code sample doesn't show how to get the values of those properties though. Use UserID=objRecordSet.Fields(&quot;samAccountName&quot;) after the Set objRecordSet = objCommand.Execute to get, for example, the samAccountName (UserID). Fill in the &quot;Fields&quot; parameter for whatever field you pulled.

If you download the ADSI SDK from Microsoft, there's a neat tool called ADSVW that lets you browse your AD structure and see the names and values of all the properties. I'm sure there's some MS published book that has all this also but who wants to pay 50 bucks for something you can easily figure out with a little help?

Glad to help put you on the path.
 
Thanks for all your help! That looks like what I need.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top