Search code examples
linuxactive-directoryldapldap-query

How to do ldapsearch with multiple filters?


I am doing an ldap search like below to get the info for a person,

ldapsearch -LLL -H ldaps://ldap.xyzcorp.com:636 -D 'xyzcorp\jack1' -W -x -b 'dc=xyzcorp,dc=com' sn=Ready

"sn" name "Ready" here is the last name of the person, but it returns multiple results who have the same last name "Ready", so I want to add multiple filters to search for both first name and last name like below:

ldapsearch -LLL -H ldaps://ldap.xyzcorp.com:636 -D 'xyzcorp\jack1' -W -x -b 'dc=xyzcorp,dc=com' sn=Ready AND givenName=Bill

but the result returned still contains multiple persons with the same last name "Ready". I am not sure which part is incorrect.

Can you please help me with this command?


Solution

  • I haven't used ldapsearch. That said, the custom LDAP query to return only the one person with sn=Ready and givenName=Bill if you can tack that onto your command would look like:

    ldapsearch -LLL -H ldaps://ldap.xyzcorp.com:636 -D 'xyzcorp\jack1' -W -x -b 'dc=xyzcorp,dc=com' "(&(objectCategory=user)(objectClass=user)(sn=Ready)(givenName=Bill))"