I have been working on a script for a few days now and I'm just not ge +tting the handle on it. One of the things I'm trying to do is read i +n a csv file that has a list of names in two columns like: "Johnson, Joe",Phyllis Ivy "Harris, Al",Maureen Murl "Farris, Allen",Sandra Norm "Daniels, Greg",Gwen Fair Next, I search AD and return their email addresses. Of course some th +em won't be found which is another problem I'm having. So since it returns some of the emails then the ones that it doesn't r +eturn it messes up the formatting. Also, what I want it to do is ret +urn the names of the people if an email address was not found. please let me know if anyone needs more information. below is the script that I am using currently: #!perl use Getopt::Long; use Net::LDAPS; use Text::CSV; ($domainCont, $surNm, $givenNm, $dispNm, $eNo, $outFlNm, $id, $pw) = ( +'', '', '','', -1, '', '', ''); &GetOptions('dc=s' => \$domainCont ,'i=s' => \$id ,'p=s' => \$pw ,'d=s' => \$baseDir ,'f=s' => \$inFlNm); my $ad = Net::LDAP->new($domainCont) or die "Can't connect to AD >$!<\ +n"; $ad->bind($id, password=>$pw) or die " bind for $id failed >$!<\n"; my $base = 'OU=People,OU=staff,DC=ad,DC=wjgilmore,DC=com'; my $attrs = "sn, givenname"; open IN, "<"."./$baseDir/$inFlNm" or die "Can't open transfers file >$ +inFlNm<\n"; $outFlNm = "test.csv"; open OUT, ">"."./$baseDir/$outFlNm" or die "Can't open transfers file +>$outFlNm<\n"; while(<IN>){ @manager = split(/"/, $_); @assist = split(/ /, $manager[2]); chop($assist[1]); @assist2 = split(/,/, $assist[0]); $assistant = "$assist[1], $assist2[1]"; $filter1 = '(displayName='.$manager[1].')'; $filter2 = '(displayName='.$assistant.')'; my $results1 = $ad->search(base=>$base,filter=>$filter1,attrs=>$attrs) +; my $results2 = $ad->search(base=>$base,filter=>$filter2,attrs=>$attrs) +; #print "$filter1\n"; foreach $adEnt ($results1->entries){ my $entry1 = $results1->entry($i1); my $mail1 = $entry1->get_value('mail'); chomp; print OUT "$manager[1],"; print OUT "$mail1,"; #printf $entry1->get_value('mail')."\n"; } foreach $adEnt ($results2->entries){ my $entry2 = $results2->entry($i2); my $mail2 = $entry2->get_value('mail'); print OUT "$assistant,"; print OUT "$mail2,\n"; #printf $entry2->get_value('mail')."\n"; } } $ad->unbind;

In reply to Match csv to AD and returning email addresses by meredib

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.