Listing05_Create_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;

my $new_site = 'RTP';

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

# This could be dynamically retrieved using RootDSE
my $new_site_dn = "cn=$new_site,cn=sites,cn=configuration,dc=xyz,dc=com";

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

print "Creating site object for $new_site\n";
$result = $ldap->add (
             dn   => $new_site_dn,
             attr => [objectclass => 'site']);
$result->code && die $result->error;
print "Done\n";

print "Creating servers container\n";
$result = $ldap->add (
             dn   => "cn=Servers,$new_site_dn",
             attr => [objectclass => 'serversContainer']);
$result->code && die $result->error;
print "Done\n";

print "Creating NTDS Site Settings object\n";
$result = $ldap->add (
             dn   => "cn=NTDS Site Settings,$new_site_dn",
             attr => [objectclass => 'nTDSSiteSettings']);
$result->code && die $result->error;
print "Done\n";

print "Creating Licensing Site Settings object\n";
$result = $ldap->add (
             dn   => "cn=Licensing Site Settings,$new_site_dn",
             attr => [objectclass => 'licensingSiteSettings']);
$result->code && die $result->error;
print "Done\n";

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

This code has been viewed 643 times.

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