Help with LDAP Search filters:
http://msdn.microsoft.com/en-us/library/aa746475(VS.85).aspx
 
By using RootDSE instead of a hardcoded domain name, it makes the script
domain name agnostic (it retrieves data for the domain you are currently
connected to), and connects to that LDAP tree (unless you are trying to
retrieve data for a domain other than the one you are currently
connected to, and then this shortcut doesn't help.

For simplicity sake, I made the directreports into a subroutine.

As well, I removed the ADSSystemInfo call, and then changed your "Email
Address" property to "mail" as that is the LDAP property for an email
address in an Exchange environment.

HTH

Steven
________________________________

        From: perl-win32-admin-boun...@listserv.activestate.com
[mailto:perl-win32-admin-boun...@listserv.activestate.com] On Behalf Of
A F
        Sent: Wednesday, November 17, 2010 12:34 PM
        To: perl-win32-admin@listserv.ActiveState.com
        Subject: Re: Perl and Net::LDAP
        
        
        One last question on this topic,
        How do I loop through all the users in AD instead of specifying
a user login name one at a time?
                
        use Win32::OLE;
         use strict;
        use warnings;
              
              my $userid = &Win32::LoginName;
                my $sysinfo = Win32::OLE->new('ADSystemInfo') || die
        ("Can't get sysinfo: " .Win32::OLE->LastError()."\n");
                my ($userDN,$first,$last);
                if ( $ARGV[0] )
                {
                  ($first,$last) = split (/\./,$ARGV[0]);
                  $userDN = "cn=$last\\,
        $first,cn=users,DC=internal,DC=compaq,DC=com";
                }
                else
                {
                  $userDN=$sysinfo->{UserName};
                }
                my $adsuser = Win32::OLE->GetObject("LDAP://$userDN") ||
        die ("Can't find user: ".Win32::OLE->LastError()."\n");
                print "CN: $adsuser->{cn}\n";
                print "Email address: $adsuser->{EmailAddress}\n";
                print "Username: $adsuser->{Samaccountname}\n";
                print "Manager: $adsuser->{Manager}\n";
                print "Direct Reports: ";
               foreach my $report ( @{$adsuser->{directReports}} ) 
               {
                  print $report,"\n";
                }
                
                
        
        

        ________________________________

        From: Steven Manross <ste...@manross.net>
        To: A F <perl95...@yahoo.com>;
perl-win32-admin@listserv.ActiveState.com
        Sent: Mon, November 15, 2010 8:30:51 PM
        Subject: RE: Perl and Net::LDAP
        
        Win32::Exchange can create Exchange 2003 mailboxes.
        
        ..and really it's just a collection of Active Directory and CDO
scripts
        to handle the Mailbox creation.
        
        FYI
        
        Steven
        
        
        ________________________________
        
            From: perl-win32-admin-boun...@listserv.activestate.com
        [mailto:perl-win32-admin-boun...@listserv.activestate.com] On
Behalf Of
        A F
            Sent: Monday, November 15, 2010 6:26 PM
            To: perl-win32-admin@listserv.ActiveState.com
            Subject: Re: Perl and Net::LDAP
            
            
            
            Thank you very much Jeremy. 
            If I can get a copy of your automated AD account creation,
that
        will be great.
            I am having 2 problems with mine
            We are still on Exchange 2003, so even I was able to
        automatically create user account in AD, I am having hard time
creation
        mailbox.
            Also I will be curious to know how you did the web based
since
        I've tried that but failed because I couldn't get the service
account
        with domain admins rights to work correctly on the web.
            
            Thanks you so much
            Alain
            
        
            ________________________________
        
            From: Jeremy Fluhmann <fluhm...@gmail.com>
            To: A F <perl95...@yahoo.com>
            Cc: James Alarie <jalar...@yahoo.com>;
        perl-win32-admin@listserv.activestate.com
            Sent: Sat, November 13, 2010 11:46:48 AM
            Subject: Re: Perl and Net::LDAP
            
            I haven't done much with Win32 and Active Directory stuff in
a
        while, but aside from that, you might use something similar to
the
        following to print out the array:
            
            ......
            print "Username: $adsuser->{Samaccountname}\n";
            print "Manager: $adsuser->{Manager}\n";
            print "Direct Reports: ";
            foreach my $report ( @{$adsuser->{directReports}} ) {
                print $report,"\n";
            }
            
            In a former job, I created an automated AD account creation
        program.  It was web-based and used Catalyst, but if you still
need help
        with your program, I'd be happy to dig up my code and share with
you.
            
            Hope that helps,
            Jeremy
            -- 
            
        
            Jeremy Fluhmann
            http://twitter.com/jfluhmann
            http://identi.ca/jfluhmann
            Open Source Symposium - http://texasoss.org/
            Texas Linux Fest - http://www.texaslinuxfest.org/
            TCEA Strategic Open Source SIG - http://sos.tcea.org/
            <http://jfluhmann.edublogs.org/> 
        
            
            
            
            On Sat, Nov 13, 2010 at 3:19 AM, A F <perl95...@yahoo.com>
        wrote:
            
        
                I am having issue on printing "Direct Reports" of a
        manager. It is printing          Direct Reports:
ARRAY(0x19a4ad4)
                How can I print the values instead of the array
        reference?
                
                use Win32::OLE;
                my $userid = &Win32::LoginName;
                my $sysinfo = Win32::OLE->new('ADSystemInfo') || die
        ("Can't get sysinfo: " .Win32::OLE->LastError()."\n");
                my $userDN;
                if ( $ARGV[0] )
                {
                  ($first,$last) = split (/\./,$ARGV[0]);
                  $userDN = "cn=$last\\,
        $first,cn=users,DC=internal,DC=compaq,DC=com";
                }
                else
                {
                  $userDN=$sysinfo->{UserName};
                }
                my $adsuser = Win32::OLE->GetObject("LDAP://$userDN") ||
        die ("Can't find user: ".Win32::OLE->LastError()."\n");
                print "CN: $adsuser->{cn}\n";
                print "Email address: $adsuser->{EmailAddress}\n";
                print "Username: $adsuser->{Samaccountname}\n";
                print "Manager: $adsuser->{Manager}\n";
                print "Direct Reports: $adsuser->{directReports}\n";
                
            
        ------------------------------------------------------------
                Also when using Net:LDAP,
                This code only print only one single "Direct Reports"'s
        name . Any idea why?
                
                use Net::LDAP;
                  
                $ldap = Net::LDAP->new( 'server.company.com:389
        <http://server.company.com:389/> ' ) or die "$@";
                $mesg = $ldap->bind;
                $user = &Win32::LoginName;
                $user = $ARGV[0];
                $mesg = $ldap->search( #
                                        base =>
        "CN=Users,DC=internal,DC=compaq,DC=com",
                                        filter =>
        "(&(samAccountname=$user) )"
                );
            
        
                $mesg->code && die $mesg->error;
                my($entry);
                @all = $mesg->entries;
                foreach $ent (@all)
                {
                  foreach $att (sort $ent->attributes )
                  {
                    if ( $att =~ m!\bmail\b! )
                      {
                        print "$att -----" . $ent->get_value($att) .
        "---\n";;
                      }
                      if ( $att =~ m!manager! )
                      {
                        print "$att ----- " . $ent->get_value($att) .
        "---\n";;
                      }
                      if ( $att =~ m!directReports! )
                      {
                        print "$att ----- " . $ent->get_value($att) .
        "---\n";;
                      }
                            
                    }
                }
                
                ________________________________
        
                From: James Alarie <jalar...@yahoo.com>
                To: A F <perl95...@yahoo.com>
                Sent: Fri, October 22, 2010 12:50:31 PM
                Subject: Re: Perl and Net::LDAP
                
                
                I don't remember having any sample code to offer anyone,
        so I tried a Google search to see what I might have had.  I
found
        multiple sites where I asked for help, but no sample code.
        
                
                
        
                The only reponses that I found that were of help to me
        mentioned that I had to be running as the System Administrator.
I do
        remember that doing that fixed my problem.
        
                
                
        
                I'm now retired and no longer have access to my work
        machine.  The only files I have on my home computer are very
early test
        files with minor sections of code as I was testing pieces.  I
don't
        expect them to be of any use, and they may contain something
considered
        PRIVATE to my previous employer.
        
                
                
        
                Sorry.  I wish I could help, but it's been seven years,
        and I don't remember much about that project.  Most of my work
since
        then has been HTML, XHTML, JavaScript, and CSS, plus a small
amount of
        VBScript.
        
                
                
        
        
                --- On Fri, 10/22/10, A F <perl95...@yahoo.com> wrote:
                
        
        
                    From: A F <perl95...@yahoo.com>
                    Subject: Re: Perl and Net::LDAP
                    To: "James Alarie" <jalar...@yahoo.com>
                    Date: Friday, October 22, 2010, 12:44 PM
                    
                    
                    Thank you very much.
                    I was googling for perl and Active directory and
        your post came up from a forum and from there I went to your web
site.
                    
        
                    ________________________________
        
                    From: James Alarie <jalar...@yahoo.com>
                    To: perl95...@yahoo.com
                    Sent: Fri, October 22, 2010 8:40:06 AM
                    Subject: Re: Perl and Net::LDAP
                    
                    
                    I haven't worked with LDAP in over six years;
        I'll have to go looking for whatever I might have saved on that.
Just
        curious:  where did you get my address with reference to this
stuff?
        
                    
                    
        
        
                    --- On Fri, 10/22/10 3:11 AM,
        perl95...@yahoo.com wrote:
                    
        
                    
                    
        
                    Hi James,
                    
                    Can you send me your sample code to create,
        modify users in Active Drectory?
                    I am having difficulties creating account.
                    
                    Thanks
                    Alai    
        
                
        
        
        


Attachment: directreports.pl
Description: directreports.pl

_______________________________________________
Perl-Win32-Admin mailing list
Perl-Win32-Admin@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to