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

Active Directory Filtering

Status
Not open for further replies.

Miked811

Programmer
Apr 17, 2005
61
CA
Hi,

I have an Active Directory that have an OU structure below.

Head Office
IT
Accounting
Finance
etc...

Where Head Office is the Root OU and the ones below are sub OUs.

This code works fine when I run it:

Code:
strBase = "<LDAP://ou=Head Office,dc=kuplax,dc=com>"

strFilter = "(&(objectCategory=person)(objectClass=user))"
    
strAttributes = "sAMAccountName,cn,userPrincipalName,"

strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False

Set adoRecordset = adoCommand.Execute

But it returns all the Users in all the sub OUs. What I only want is to return Users from certain sub OUs, e.g. IT.

How can I further filter the sub OUs, please help.

Thanks

Mike
 
>How can I further filter the sub OUs, please help.
You've to bind to the ou directly like this (ou: IT, for instance)
[tt]strBase = "<LDAP://[blue]ou=IT,[/blue]ou=Head Office,dc=kuplax,dc=com>"[/tt]
rather than restricting further the filter. ou is not exposed to the object as an attribute, hence, there is no way to narrow down the filter to the specific sub ou.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top