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

ldap query - can't get desired values

Status
Not open for further replies.

kokser

Programmer
Sep 25, 2009
90
DK
I decided that it was a pita to change the script for every domain, so googling aroud I found that almost everywhere the scripts finds the information itself. This part was easy to get working, however, it no longer pulls out all the values I need.

Current functioning code
Code:
objCommand.CommandText = _
"SELECT Name, sAMAccountName, mail, proxyAddresses, homeDirectory, homeDrive, memberOf, scriptPath, ObjectClass, UserAccountControl FROM 'LDAP://dc=AdvizorIT,dc=local' WHERE objectCategory='Person'"
Set objRecordSet = objCommand.Execute


Current non-functioning code
Code:
Set rootDSE = GetObject("LDAP://RootDSE")
DomainContainer = RootDSE.Get("defaultNamingContext")

ldapStr = "<LDAP://" & DomainContainer & ">;(objectCategory=person);adspath;subtree"
Set objRecordSet = conn.Execute(ldapStr)

I can't get this output, like I could before
Code:
Wscript.Echo objRecordSet.Fields("Name").Value


The error:
Code:
Item Cannot be found in the collection corresponding to the requested name or ordinal

I understand that it cannot do this due to not having pulled out all the values like before, but I cannot figure out how to pull these values out with the new query.

Any ideas?
 
I've lost track of what we're trying to achieve ... do we want contacts? Not want contacts? To be able to distinguish between contacts and users?

WHERE objectCategory='Person' and objectClass='User'

and

WHERE objectCategory='Person' and objectClass='Contact'

should work to return lists of Users and Contacts respectively
 
Since contacts do not have samaccountnames, using the string tsuji provided will do the same as the string strongm provided.

Both of them worked well, and my script works as intended now :)

Thank you all very much for helping me so much! I'm sure I'll be back with my next script :p
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top