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. |