in reply to Accessing Exchange Address Book from Perl

I have been working with exchange and perl for a couple of years now and I've learned at least one thing: It ain't easy!! But I'm sure you will find that out for yourself if you haven't already. Now that I've gotten that out of the way, try this on for an example:
#!c:\perl\bin\perl.exe -w use strict; use warnings; use diagnostics; use Net::LDAP; #The following will be different depending on your mail server my $mailserver = "mail.company.com"; #internet accessible name of the +server my $port = 389; #LDAP port number my $org = "organization"; #Top level Exchange Organization (o) my $site = "site"; #Actual exchange site my $ldap = Net::LDAP->new($mailserver,port=>$port) or die "$@"; my @Attrs = (); # request all available attributes to be returned. my $result = $ldap->search ( base => "cn=Recipients,ou=$site,o=$org", scope => "sub", filter => "cn=*", attrs => \@Attrs ); my @entries = $result->entries; foreach my $entr ( @entries ) { print "DisplayName: ",$entr->get_value('cn'),"\n"; print "Department: ",$entr->get_value('department'),"\n"; print "Email: ",$entr->get_value('mail'),"\n"; print "#-------------------------------\n"; } $ldap->unbind(); exit;
Update:
I got this to work on both win2K and linux.

Replies are listed 'Best First'.
Re: Re: Accessing Exchange Address Book from Perl
by qadwjoh (Scribe) on Oct 16, 2003 at 10:14 UTC
    Thanks Chris,

    got your code to work, but had to install Net::LDAP and all it's required modules by hand...

    Just a couple of questions though - I'm specifically looking for one user, based on their email address |(or full name) and I only need to know their department details. Do I have to load all information about all employees - it's a pretty big company and I'm worried about memory and performance issues. Is it possible to request information on just one person?

    thanks,
    A

    UPDATE:
    Got this to work by changing the base to just "o=$org", and changing the filter to "(&(cn=*) (uid=$uid))". I also added "$entr->dump" to get all the values stored.