williey
Technical User
- Jan 21, 2004
- 242
Has anyone successfully added images to Active Directory.
Tried the following code but the image does not show up in Outlook address book. The code runs fine without error.
To verify if the image is properly inserted. I used the following code to output the image back to a file
Tried the following code but the image does not show up in Outlook address book. The code runs fine without error.
Code:
use lib qw(c:\projects\scripts);
use strict;
use warnings;
use DBI;
use lib;
use Net::LDAP qw(:all);
my $filename='c:\projects\photo.jpg';
#($filename) [EMAIL PROTECTED];
open(FH, "$filename") or die "File does not exist: $filename !";
binmode(FH);
my $c=0;
my $photo;
while (<FH>)
{
$c++;
$photo=$photo.$_;
print "NEXT: $c\n";
}
close(FH);
my $ldap;
my $mesg;
my $results;
my $err;
$ldap=Net::LDAP->new('test.server.com') or die("Could not connect to LDAP server");
my $dn='cn=Doe\, John J.,ou=users,ou=level2,dc=aaa,dc=bbb,dc=ccc';
#Connect to Active Directory server
$mesg=$ldap->bind("yyy", password=>"xxx");
$results=$ldap->modify( $dn, replace => { thumbnailPhoto => "$photo" } );
$err=$results->code;
print "ERR: $err\n";
To verify if the image is properly inserted. I used the following code to output the image back to a file
Code:
use lib qw(c:\projects\scripts);
use strict;
use warnings;
use DBI;
use lib;
use Net::LDAP qw(:all);
my $base='ou=users,ou=level2,dc=aaa,dc=bbb,dc=ccc';
my $ldap;
my $mesg;
my $results;
my $err;
my $entry;
my $t;
$ldap=Net::LDAP->new('test.server.com') or die("Could not connect to LDAP server\n");
$results=$ldap->ldapbind() || die "Bind Failed:$@";
my @attr=("thumbnailPhoto");
my $filter="(&(objectclass=User)(cn=Doe, John J.))";
my $scope='subtree';
$mesg=$ldap->search(base =>$base, scope=>$scope, filter=>$filter)
or die "Search Failed using Filter: $filter$@";
my $count=$mesg->count;
print("Found: $count\n");
foreach $entry ($mesg->all_entries)
{
$t=$entry->get("thumbnailPhoto");
}
my $filename='c:\projects\outphoto.jpg';
open(OUT, ">$filename") or die "File does not exist: $filename !";
binmode(OUT);
foreach(@$t)
{
print OUT "$_";
}
close(OUT);
$ldap->unbind;