This example runs thru employeeID but you can cut that out if you want.

use Net::LDAP;
use Net::LDAP::Util qw(ldap_error_name ldap_error_text);

my $admin = 'CN=Admin,OU=DEN,OU=Facilities,DC=corp,DC=company,DC=com';
my $base = 'DC=corp,DC=company,DC=com';
my $ldapserver = 'ldapsrv.corp.company.com';
my $password = 'password';
my $version = 3;
my $scope = 'sub';
my $ldap = Net::LDAP->new($ldapserver) or die "$@";
my $mesg = $ldap->bind ( dn => $admin, password => $password, version  => $version);
   die($mesg->error) if $mesg->code;
        open (OUT, '>  myout.csv') or die "Error opening $@";
     foreach my $empcount (0 to 31000)
        my $filter = "(&(objectclass=*) (employeeID=A*) (mail=*))";
        $mesg = $ldap->search( scope  => $scope,
                               base   => $base,
                               sizelimit => 0,
                               attrs  => ['employeeID', 'mail'],
                               filter => $filter);
        die($mesg->error) if $mesg->code;
# RESULTS
foreach my $entry ($mesg->entries) { 
                print OUT $entry->get_value('employeeID');
                print OUT ",";
                print OUT $entry->get_value('mail') . "\n";
   }
        close (OUT);
#       print "\n\nReturn code: ",$mesg->code ;
#        print "\n\tMessage: ", ldap_error_name($mesg->code);
#        print "\n\t\t ",        ldap_error_text($mesg->code);
#        print "\nMessageID: ",$mesg->mesg_id;
#        print "\n\tDN: ",$mesg->dn;
#

printf("====\nFound %d entries\n", $mesg->count);


Thank you,

Patrick Sullivan

-----Original Message-----
From: Messenger, Mark [mailto:[EMAIL PROTECTED]
Sent: Tuesday, July 01, 2003 2:43 PM
To: 'AS-Win32-Admin'
Subject: Pulling Email Address from ADSI?


Does anyone know a way to use Win32::OLE (or any other module, for that
matter) to pull the Active Directory field known as "E-mail" in AD Users and
Computers?  (The SMTP address associated with an account)

Up to this point, I've been shelling out to a VBS (I feel dirty).  A snippet
follows, as it may be of assistance:


On Error Resume Next
set objArgs=WScript.Arguments
strusername=objArgs(0)
strfullname=objArgs(1)
strMyOU=objArgs(2)

ldapstr="LDAP://cn="; & strusername & ",OU=Users,ou=" & strMyOU &
",ou=Support,dc=DIRECTV,dc=com"
Set objUser = GetObject (ldapstr)
objUser.GetInfo
strphnum = objUser.Get("mail")
WScript.echo "email: " & strphnum & " ##$"



Danke :)
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs




This communication is for the use of the intended recipient only.  It may contain 
information that is privileged and confidential.  If you are not the intended 
recipient of this communication, any disclosure, copying, further distribution or use 
thereof is prohibited.  If you have received this communication in error, please 
advise me by return e-mail or by telephone and delete/destroy it.


_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to