Move DC to different site (Perl)

This code can be found in Chapter 3 of Active Directory Cookbook, 2nd edition

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.

# This Perl code moves a domain controller to a different site

# ---------------------------------------------------------------
# Adapted from VBScript code contained in the book:
#      "Active Directory Cookbook" by Robbie Allen
# Publisher: O'Reilly and Associates
# ISBN: 0-596-00466-4
# Book web site: http://rallenhome.com/books/adcookbook/code.html
# ---------------------------------------------------------------

# ------ SCRIPT CONFIGURATION ------
my $strDCName      = "<DomainControllerName>";  # e.g. dc2
my $strCurrentSite = "<CurrentSiteName>";       # e.g. Default-First-Site-Name
my $strNewSite     = "<NewSiteName>";           # e.g. Raleigh
# ------ END CONFIGURATION ---------
use Win32::OLE;
$Win32::OLE::Warn = 3;
my $strConfigDN = Win32::OLE->GetObject("LDAP://RootDSE")->Get("configurationNamingContext");
my $strServerDN = "LDAP://cn=" . $strDCName . ",cn=servers,cn=" . 
                  $strCurrentSite . ",cn=sites," . $strConfigDN;
my $strNewParentDN = "LDAP://cn=servers,cn=" . $strNewSite . ",cn=sites," . $strConfigDN;
my $objCont = Win32::OLE->GetObject($strNewParentDN);
$objCont->MoveHere($strServerDN, "cn=" . $strDCName);
print "Successfully moved $strDCName to $strNewSite\n";

This code has been viewed 1183 times.

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