williey
Technical User
- Jan 21, 2004
- 242
Currently, I'm working on adding, changing, deleting and searching the Active Directory using Perl.
But I get the following error when I try to add.
Line 44 is
Here is the compelte code.
But I get the following error when I try to add.
Code:
Global symbol "$ldap" requires explicit package name at bind.pl line 44, <DATA> line 225.
Line 44 is
Code:
$results = $ldap->add('cn=Jane Doe, ou=retail, ou=users, ou=level2, dc=test, dc=lab',
attr=>['cn' => 'Jane Doe',
'sn' => 'Doe',
'mail' => 'jdoe@cnb.lab',
'objectclass' => ['top', 'person', 'organizationalPerson', 'user'],
]);
Here is the compelte code.
Code:
use Net::LDAP;
use strict;
my $connect=Net::LDAP->new('server01.test.lab')
or die("Could not connect to LDAP server");
#Connect to server
my $mesg=$connect->bind("admin\@test.lab", password=>"pass");
#What is the search base?
my $base='ou=retail,ou=users,ou=level2,DC=test,DC=lab';
my $scope="subtree";
#What are we searching for?
my $filter="(&(objectclass=User))";
#What attributes should be returned?
my $attrs="sn";
#Execute the search
my $results=$connect->search(base=>$base, scope=>$scope, filter=>$filter, attrs=>$attrs);
my $count=$results->count;
print("Total entries returned: $count\n");
#Display entries
my $entry;
for (my $i=0; $i<$count; $i++)
{
$entry=$results->entry($i);
print $entry->get_value('sn') . ", " .
$entry->get_value('givenname') . " " .
$entry->get_value('userprincipalname') . " " .
$entry->get_value('sAMAccountname') . "\n";
}
$results = $ldap->add('cn=Jane Doe, ou=retail, ou=users, ou=level2, dc=test, dc=lab',
attr=>['cn' => 'Jane Doe',
'sn' => 'Doe',
'mail' => 'jdoe@cnb.lab',
'objectclass' => ['top', 'person', 'organizationalPerson', 'user'],
]);
$results->code && warn "failed to add entry: ", $results->error;
#Unbind from server
$mesg=$connect->unbind;