Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have around 10 users who have been given access to one specific application which uses AD authentication.

ldapsearch -p xxx -LLL -x -w test -h -D abc -b dc=abc,dc=com sAMAccountName=xyz | grep displayName

Can sAMAccountName be made to refer to my entire list of users (which is a seperate text file) at once? If not, Can we just put this command into a script and let the user enter their sAMAccountName and check if they exist in AD?

Any thoughts on this...

share|improve this question
up vote 0 down vote accepted

I might not understand this clearly but if you wanted to put it in a script you could write a bash script like below to prompt for an account name.

echo -n "Please enter username to lookup: "
DISPLAYNAME=`ldapsearch -p xxx -LLL -x -w test -h -D abc -b dc=abc,dc=com sAMAccountName=$USERNAME | grep displayName`

if [ -z "$DISPLAYNAME" ]; then
  echo "No entry found for $USERNAME"
  echo "Entry found for $USERNAME"
share|improve this answer

Your script will have to create a proper LDAP filter with all the usernames:


For example:

while read -r name; do

(| ... ) is OR in LDAP. The AND operator is (& ... ).

share|improve this answer

Your Answer


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.