Just throwing this out there; If you are querying Active Directory you will run into<br>the 1000 results per query limit.  Look into using Net::LDAP::Control::Paged<br>to help with this.<br><br>Here is an example<br><br><pre>
sub paged_query
{
    my ( $ldap, $args, $page_size ) = @_;
    my ( @entries, $cookie );

    $page_size = 100 if ( !defined $page_size || $page_size < 1 );
    my $page = Net::LDAP::Control::Paged->new( size => $page_size );
    push(@$args, (control => [$page]));

    my $mesg;

    while ( $mesg = $ldap->search(@$args) ) {
        last if ( $mesg->code );
        push(@entries, $e) for my $e ( $mesg->entries );
        last unless ( my ($resp) = $mesg->control(LDAP_CONTROL_PAGED) );## list context! `my ($resp)`
        last unless ( $cookie = $resp->cookie );
        $page->cookie($cookie);
    }

    warn $mesg->error if ( $mesg->code );

    if ($cookie) {
        $page->cookie($cookie);
        $page->size(0);
        $ldap->search(@$args);
        die 'LDAP Search error';
    }
    return ( \@entries );
}</pre><br><div class="gmail_quote">On Thu, Mar 8, 2012 at 12:05 PM, Bill Brush <span dir="ltr"><<a href="mailto:bbrush@gmail.com">bbrush@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Well it's essentially finished, so I thought I'd share.  I'm sure it<br>
could be improved, but honestly I'm just impressed I got it to work.<br>
Now I just need to tweak it to work in unattended cron mode.<br>
<br>
I sanitized the code so none of my particulars are there, for obvious<br>
reasons.  Big thanks to Jay for pointing me towards the Email::Stuff<br>
module.<br>
<br>
Bill<br>
<br>
***************************************************************************************************************<br>
<br>
#!/usr/bin/perl<br>
<br>
<br>
use strict;<br>
use Net::LDAP;<br>
use IO::File;<br>
use Email::Stuff;<br>
<br>
#Creates connection to netusrA on the LDAP port, using the ldap_binder account<br>
my $netad = Net::LDAP->new("myhost.mydomain") or die "Could not connect! $!";<br>
$netad->bind("bind account here", password=>"bind account password here");<br>
<br>
#Defines the LDAP search to start at the root of the directory tree<br>
my $base = 'root of my LDAP directory tree';<br>
<br>
#The filter is in LDAP format<br>
#The filter specifies users that have an SN (last name) that exists,<br>
but is not equal to System nor starts with Sharepoint<br>
#AND that have an email address<br>
#AND that have a givenname (first name) that is not equal to NET<br>
my $filter = "(&(&(!(sn=System))(!(sn=Sharepoint*))(sn=*))(mail=*)(&(!(givenname=NET))(givenname=*)))";<br>
<br>
# $attrs specifies which attributes to be retrieved<br>
my $attrs = ["givenname","sn","mail"];<br>
<br>
# This creates a search result object ($results) from the netad search method<br>
my $results = $netad->search(base=>$base,filter=>$filter,attrs=>$attrs);<br>
<br>
# This uses the count method of $results to return the number of<br>
records matching the filter<br>
my $count = $results->count;<br>
<br>
<br>
<br>
#message ("Records returned $count");<br>
<br>
<br>
<br>
#Creates an output file named emailList.csv or returns error.<br>
my $outputfile = IO::File->new("emailList.csv","w") or die "Could not<br>
open output file $!";<br>
<br>
#Loop to write each result line to the output file<br>
for (my $i=0;$i<$count;$i++){<br>
<br>
        #Assigns the result at $i to the variable $foo<br>
        my $foo = $results->entry($i);<br>
                #Assigns the attribute names to variables<br>
                my $sn="sn";<br>
                my $gn="givenName";<br>
                my $mail="mail";<br>
<br>
                #Assigns the value from $foo to a specific variable<br>
                my $lastname = $foo->get_value($sn);<br>
                my $firsttname = $foo->get_value($gn);<br>
                my $email = $foo->get_value($mail);<br>
<br>
                #Concatenates the variables to a csv output line.  The \n is the new<br>
line operator<br>
                my $line = "$firsttname,$lastname,$email\n";<br>
<br>
#  Writes the same output to the screen<br>
#               message ("$line");<br>
<br>
                #Writes the data line to the output file<br>
                $outputfile->print($line);<br>
<br>
}<br>
<br>
#Closes the output file<br>
undef $outputfile;<br>
<br>
#Closes the LDAP connection<br>
$netad->unbind;<br>
<br>
#Email the output file to the SharePoint doc library using the SMTP server<br>
Email::Stuff->To('destination e-mail')<br>
                        ->from('source e-mail')<br>
                        ->Subject("Automatically generated e-mail list")<br>
                        ->text_body("E-mail list for Communications department.  Used for<br>
Constant Contact service.")<br>
                        ->attach_file('emailList.csv')<br>
                        ->using('SMTP',Host => 'my mail server')<br>
                        ->send;<br>
<br>
<br>
sub message<br>
{<br>
    my $m = shift or return;<br>
    print("$m\n");<br>
}<br>
_______________________________________________<br>
Omaha-pm mailing list<br>
<a href="mailto:Omaha-pm@pm.org">Omaha-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/omaha-pm" target="_blank">http://mail.pm.org/mailman/listinfo/omaha-pm</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>Ted Katseres<br>      ||=O=||<br>