If the plugin works for you I am happy for you.
If not then here is the magic stuff from my bash script:
while read line
do
accntname=$(mysql -u$DBUSR -p$DBPWD -s -N $DBNAME -e "select meta_value from wp_usermeta where user_id = $line and meta_key = 'adi_samaccountname';")
id=$(mysql -u$DBUSR -p$DBPWD -s -N $DBNAME -e "select meta_value from wp_usermeta where user_id = $line and meta_key = 'wp_user-settings-time'")
if [ -z $id ]
then
id=$(mysql -u$DBUSR -p$DBPWD -s -N $DBNAME -e "select unix_timestamp(user_registered) from wp_users where id = $line")
mysql -u $DBUSR -p$DBPWD -s -N $DBNAME -e "insert ignore into wp_usermeta (user_id, meta_key, meta_value) values ($line, 'wp_user-settings-time', $id)"
fi
accntthmb=$(mysql -u$DBUSR -p$DBPWD -s -N $DBNAME -e "select meta_value from wp_usermeta where user_id = $line and meta_key = 'thumbnailphoto';")
if [ -n "$accntthmb" ]
then
echo $accntthmb | base64 --decode > /var/www/html/wp-content/uploads/avatars/$accntname_avatar_$id.jpg
chown apache:apache /var/www/html/wp-content/uploads/avatars/$accntname_avatar_$id.jpg
insertentry="https://$localip/wp-content/uploads/avatars/${accntname}_avatar_$id.jpg"
entrysize=${#insertentry}
insertstring="a:1:{s:4:\"full\";s:$entrysize:\"$insertentry\";} "
exists=$(mysql -u$DBUSR -p$DBPWD -s -N $DBNAME -e "select meta_value from wp_usermeta where user_id=$line and meta_key=\"simple_local_avatar\";")
if [ -n "$exists" ]
then
mysql -u$DBUSR -p$DBPWD -s -N $DBNAME -e "update wp_usermeta set meta_value='$insertstring' where user_id=$line and meta_key='simple_local_avatar'"
else
mysql -u$DBUSR -p$DBPWD -s -N $DBNAME -e "insert into wp_usermeta (user_id,meta_key,meta_value ) values ($line,'simple_local_avatar','$insertstring')"
fi
fi
done < <(mysql -u$DBUSR -p$DBPWD -s -N $DBNAME -e "select user_id from wp_usermeta where meta_key='adi_whenchanged' and meta_value > '$lastupdate';")
As you can see I have set a few other variables prio to the above, like $lastupdate, $DBUSR, $DBPWD, $DBNAME, $localip