Newbie: LDAP Query question

  • Thread starter Thread starter MIchael Bals
  • Start date Start date
M

MIchael Bals

Hi,

I am new to all the active direcetory and LDAP stuff. My problem is,
that I want to perform a simple search and don't really know how to
create the query statement.

The active directory structure is as follows

dc=company
ou=x
ou=y
cn=test user
cn=test user2
cn=test user3
ou=z
cn=test user4

I am conntecion just to the root of the active directory server, like
ldap://HVNTDC004. How can I find all persons belonging to 'y'? In
other words how can I find all persons,users beloging to a specific
'OU' ? I have tried filter strings like (&(objectClass=user)(ou=y))
and stuff like this but no luck.

Any help is welcome, I din't really find anything in the web for this
kind of search.

Greetings
Mike
 
The easiest way to search AD is to use ADO query. So the answer to your question would be

Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"

Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection

objCommand.CommandText = _
"<LDAP://ou=y,ou=x,dc=company>;(objectCategory=person);name;subtree"Set objRecordSet = objCommand.Execute

While Not objRecordSet.EOF
Wscript.Echo objRecordSet.Fields("name")
objRecordSet.MoveNext
Wend

objConnection.CloseThis will list all users, persons inside ou and below. Instead of name, you can specify attributes that you want query to return. Separate them by coma.

--
Regards

Matjaz Ladava, MCSE (NT4 & 2000), Windows MVP
(e-mail address removed)
http://ladava.com
 
Back
Top