Skip to content

Instantly share code, notes, and snippets.

@walquis
Last active May 4, 2020 20:09
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save walquis/4549090 to your computer and use it in GitHub Desktop.
Save walquis/4549090 to your computer and use it in GitHub Desktop.
Retrieve a photo from Active Directory with ldapsearch (Linux).
SERVER="dc1.us.yourcompany.com"
DN="CN=aUserLogin,OU=SomeOrgUnit,OU=AnotherOrgUnit,DC=dc1,DC=us,DC=yourcompany,DC=com"
PASSWORD="aUserLoginsPassword"
OU="ou=AnotherOrgUnit,dc=us,dc=yourcompany,dc=com"
ldapsearch -h "$SERVER" -p 389 \
-x -D "$DN" -w "$PASSWORD" \
-t -s sub -b "$OU" "(&(objectClass=user)(sAMAccountName=anotherUserLogin))" "thumbnailPhoto"
# Or, get all the users in one go...
ldapsearch -h "$SERVER" -p 389 \
-x -D "$DN" -w "$PASSWORD" \
-t -s sub -b "$OU" "(&(objectClass=user)(thumbnailPhoto=*))" "sAMAccountName" "thumbnailPhoto"
@gadkarisid
Copy link

Might be a dumb question, but where are the photos being stored? Is it just the working directory of the bash script?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment