Listing17_Moving_Server (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;

# Move information
my $dc       = 'dc2';
my $new_site = 'RTP';
my $old_site = 'Default-First-Site-Name';
my $sites_dn = 'cn=sites,cn=configuration,dc=xyz,dc=com';

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

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

print "Moving server $dc\n";
$result = $ldap->moddn("cn=$dc,cn=Servers,cn=$old_site,$sites_dn",
                        newsuperior  => "cn=Servers,cn=$new_site,$sites_dn",
                        newrdn       => "cn=$dc",
                        deleteoldrdn => 1);
$result->code && die $result->error;
print "Server move complete\n";
$ldap->unbind;

This code has been viewed 613 times.

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