Listing07_Delete_Site (Perl)

This code can be found in Chapter 9 of Managing Enterprise Active Directory Services

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the Perl code from this site.

# From the book "Managing Enterprise Active Directory Services"
# ISBN: 0-672-32125-4

use strict;
use Net::LDAP;
use Net::LDAP::Control;

my $old_site = 'RTP';

my $server  = 'dc1.xyz.com';
my $user    = 'administrator@xyz.com';
my $passwd  = 'password';

# This could be dynamically computed using RootDSE
my $old_site_dn = "cn=$old_site,cn=sites,cn=configuration,dc=xyz,dc=com";

my $ldap = Net::LDAP->new($server, version=>3) or die "$@";
my $result = $ldap->bind($user, password => $passwd);
$result->code && die $result->error;

print "Deleting site container for $old_site\n";

# Since the site container will have child objects
# the delete tree control must be used
my $ctrl = Net::LDAP::Control->new(
            type     => "1.2.840.113556.1.4.805", # OID for delete tree ctrl
            value    => '',
            critical => 0,
           );
$result = $ldap->delete($old_site_dn,control => [ $ctrl ]);
$result->code && die $result->error;

print "Site deletion complete\n";
$ldap->unbind;

This code has been viewed 608 times.

New from the creators of TechTasks.com: StatSheet.com