Newbie: LDAP Query question

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
 
M

Matjaz Ladava [MVP]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top