LISTING 2: Code That Deletes Objects use strict; use Net::LDAP; # BEGIN CALLOUT A BEGIN COMMENT # Customize for your environment. END COMMENT my $dc = 'dc1'; my $user = 'administrator@mycorp.com'; my $passwd = 'Adminpasswd'; my $parent_dn = 'ou=Contacts,dc=mycorp,dc=com'; # END CALLOUT A BEGIN COMMENT # Connect and authenticate. END COMMENT my $ldap = Net::LDAP->new($dc) or die "$@\n"; my $rc = $ldap->bind( $user, password => $passwd); die $rc->error if $rc->code; # BEGIN CALLOUT B BEGIN COMMENT # Find all contact objects in $parent_dn. END COMMENT my $search = $ldap->search ( base => $parent_dn, scope => 'one', filter => "(objectClass=contact)", attrs => ['cn'], ); die $search->error if $search->code; # END CALLOUT B # BEGIN CALLOUT C BEGIN COMMENT # Delete all matching objects. END COMMENT my $count = 0; foreach my $entry ($search->entries) { $rc = $ldap->delete( $entry->dn ); if ($rc->code) { print "Delete failed for ",$entry->get_value('cn'),": ",$rc->error,"\n"; } else { $count++; print "Delete successful: ",$entry->get_value('cn'),"\n"; } } print "Total successfully deleted: $count\n"; # END CALLOUT C $ldap->unbind;