Skip to content

Instantly share code, notes, and snippets.

@scottsbaldwin
Created February 1, 2012 21:37
Show Gist options
  • Save scottsbaldwin/1719621 to your computer and use it in GitHub Desktop.
Save scottsbaldwin/1719621 to your computer and use it in GitHub Desktop.
active directory search
#!/bin/sh
if [ "$1" == "" ]
then
echo "USAGE: $0 [search_term]"
exit
fi
HOST=foo.bar
ADMIN_USERNAME=DOMAIN\user
ADMIN_PASSWORD=mypass
# change the ou to match your active directory (and the dc parts)
BASE_DN="ou=Corp,dc=foo,dc=bar"
SEARCH_TERM=$1
ldapsearch -x -LLL -h ${HOST} -D ${ADMIN_USERNAME} -w ${ADMIN_PASSWORD} -b ${BASE_DN} -s sub "(sAMAccountName=${SEARCH_TERM})" cn mail sAMAccountName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment