Using ldapsearch to query Active Directory
From NippAero
Using ldapsearch to query Active Directory.
Ldap.conf
Set the ldap server and search base in /etc/ldap.conf.
Example of ldap.conf
linux:/home/mnipp # cat /etc/ldap.conf # # This is the configuration file for the LDAP nameservice # switch library and the LDAP PAM module. # # Your LDAP server. Must be resolvable without using LDAP. # Multiple hosts may be specified, each separated by a # space. How long nss_ldap takes to failover depends on # whether your LDAP client library supports configurable # network or connect timeouts (see bind_timelimit). host serverhost.domain.com # The distinguished name of the search base. base DC=domain,DC=com
Example #1
Search for a userand and return my city, state, address and telephone number.
linux:/home/mnipp # ldapsearch -LLL -x -D "CN=John Public,OU=Users,OU=Boise,OU=Users,DC=domain,DC=com" -W "sAMAccountName=mnipp" cn streetAddress l st telephoneNumber
Example #2
Search all the users with st=Idaho:
linux:/home/mnipp # ldapsearch -LLL -x -D "CN=John Public,OU=Users,OU=Boise,OU=Users,DC=domain,DC=com" -W "st=ID" cn |grep cn
