Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am writing a LDAP query in Active Directory.

I want to search a user in Active Directory in Specific OU.

I run LDAP Query (&(&(objectCategory=organizationalUnit)(objectClass=organizationalUnit)(ou=Hosted*)SAMAccountName=vvishwakarma)) but didn't work

Remember I want to search SAMaccount in specific OU not entire Directory

share|improve this question
4  
you really need more info - what does 'but didn't work' mean. are you authenticated against the AD server? –  Rich Homolka May 16 '12 at 21:10
    
We're still waiting for more information on what results you get –  uSlackr May 23 '12 at 11:05
add comment

2 Answers

first off, You are using the wrong objectcategory & objectClass. You can probably leave out the objectcategory & class all together unless there is a chance there is a group with the same samAccountname.

What does this give you?

(&(objectClass=user)(ou=Hosted*)(SAMAccountName=vvishwakarma))
share|improve this answer
    
The above LDAP query was not worked either. –  user128364 May 23 '12 at 3:29
    
I want to build a LDAP query in Active Directory to search sAMAccountName in specific OU. Anyone help me out .... –  user128364 May 23 '12 at 3:30
    
You still don't tell us what results you get. "not worked" isn't much help. –  uSlackr May 23 '12 at 11:04
add comment

I hope this will solve at least some of your problems.

The first thing you need to do is remove incorrect objectCategories and objectClasses.

Next you should set your searchDN to the root of OU you wish to search:

For example, if you wish to search through your:

domain.local
    |- OUNameLvl1
        |-OUNameLvl2

SearchDN=OU=OUNameLvl2,OU=OUNameLvl1,DC=domain,DC=local

Then you can try with:

(&(objectCategory=person)(objectClass=user)(sAMAccountName=vvishwakarma))

EDIT: I just realized you said you're doing this in Active Directory.

If using Active Directory Users and Computers, you can define a custom query where you will do the same as described above - place your search root to OU you wish to search through and then use the same LDAP query.

share|improve this answer
    
how do I add SearchDN=OU=OUNameLvl2,OU=OUNameLvl1,DC=domain,DC=local and (&(objectCategory=person)(objectClass=user)(sAMAccountName=vvishwakarma)) in one query –  user128364 Jun 10 '12 at 12:41
    
You cannot. The only attribute that contains this information as a value is distinguishedName and it is build like this: distinguishedName=CN=CONTAINER_NAME,OU=OUNameLvl2,OU=OUNameLvl1,DC=domain,DC=loc‌​al. In your case the filter should look like this: distinguishedName=*OU=OUNameLvl2,OU=OUNameLvl1,DC=domain,DC=local. Unfortunately, as explained here this attribute does not accept wildcards. More info can be found here. –  Robert Schmidt Jun 13 '12 at 15:44
    
I must correct myself on the answer above since after some research I discovered that depending on the organization of your AD you can try to filter on "memberOf" field which should be defined for every CN. This should lead you to some results: (&(objectCategory=person)(objectClass=user)(sAMAccountName=vvishwakarma)(memberO‌​f=CN=OUNameLvl2,OU=OUNameLvl1,DC=domain,DC=local)). Please let me know about the results. –  Robert Schmidt Jun 21 '12 at 13:18
    
Any luck using the info from answers to resolve your problem? –  Robert Schmidt Jul 5 '12 at 6:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.