I am trying to write a script to do some work with Active Directory. Since my scripts need to run on a Linux machine, I have to use Net::LDAP.

I have been going through previous postings and have found some useful information, but I am still having trouble. I took some code I wrote that talked to an OpenLDAP server and am trying to adapt it for our AD. I'm simply trying to bind to the AD and display some data since I want to make sure I can successfully bind and do some useful things before I get ahead of myself and try to write any additional code.

When I run the code I can tell I am binding because I don't get error messages (I do get an error if I put in a bogus server).

When I run the script I get no output. Simply nothing happens. Since I'm not getting any good diagnostic info, I'm having a hard time figuring out where to begin troubleshooting.

The OU SubOU has 1 test user account in it, as well as another OU. So I should be getting info on that one account.

Any help would be appreciated.

#!/usr/bin/perl

use Net::LDAP;

my $uid = "username";
my $bindPass = "blah";
my $ldapServer = "ldaps://ad.myorg.edu";


$ldap = Net::LDAP->new ( $ldapServer ) or die "$@";

$ldap->bind($uid, password =>$bindPass);

$mesg = $ldap->search(filter=>"(OU=SubOU,OU=myOU)", base=>"dc=ad,dc=myorg,dc=edu");

@entries = $mesg->entries;
foreach $entry (@entries) {

 print "Name: " . $entry->get_value("givenname") . "\n";
 print "Email: " . $entry->get_value("mail") . "\n";
 print "Phone: " . $entry->get_value("telephonenumber") . "\n";

}
$ldap->unbind;

Reply via email to