nbalonso.com

Extract Pictures From Ldap

| Comments

Short post to share a script that extracts the pictures from AD or OD you are bound to.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/sh

#extracts all the pictures from the connected LDAP servers
# Noel B. A. [email protected]

# line 16
# OD uses JPEGPhoto
# AD uses dsAttrTypeNative:thumbnailPhoto


USERLIST=`dscl /Search -list Users | grep -v '^_'`

# Create the folder to store the pics
mkdir ./ldappics 2>/dev/null

for SHORTNAME in ${USERLIST} ; do
  PICTURE=`dscl /Search -read Users/"${SHORTNAME}" dsAttrTypeNative:thumbnailPhoto 2>/dev/null | tail -1`
  if [[ ! ${PICTURE} == "" ]]; then
    echo "saving ${SHORTNAME}.jpg"
    echo ${PICTURE} | xxd -r -p > ./ldappics/"${SHORTNAME}".jpg
  #else
    #echo "${SHORTNAME} does not have a picture"
  fi
done

echo "Done!"

exit 0

Comments