Force Exchange to run the topology discovery process (Perl)

This code can be found in Chapter 3 of Exchange Server Cookbook

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 script was adapted from a VBScript originally published in 
# the Exchange Cookbook, (http://www.exchangebookcook.com). Written by 
# Paul Robichaux, Missy Koslosky, and Devin Ganger. Redistributed with
# permission of the publisher, O'Reilly & Associates.

# This code removes all existing instances of the Exchange_DSAccessDC object.
# Doing so forces Exchange to re-run the topology discovery process. 
# ------ SCRIPT CONFIGURATION ------

use Win32::OLE qw(in);

$strServer = 'batman';
# ' "<ServerFQDN>"  ' e.g. xch01.foobar.com
$strDC = 'batman';
# ' "<DomainControllerFQDN>" ' e.g. dc01.foobar.com
$configType = 0;
# 0 = manual; 1 = automatic
# ------ END CONFIGURATION ---------

# Get the Exchange Namespace WMI object
$objWMIExch = Win32::OLE->GetObject('winmgmts:{impersonationLevel=impersonate}!//' . $strServer . '/root/MicrosoftExchangeV2');

# Get the list of Exchange_DSAccessDC instances and iterate through them
# to modify their properties; all instances of this Type will become manually
# configured.
$listDCInst = $objWMIExch->InstancesOf('Exchange_DSAccessDC');
For($each);
objDCInst($in);
listDCInst();
$objDCInst->{Type} = $configType;
$objDCInst->PutNext();

# Delete all manually configured instances of one Type so that the discovery
# state is reset to Automatic and triggers topology discovery
foreach my $objDCInst (in $listDCInst) {
    if (($objDCInst->ConfigurationType == $configType)) {
        print "    \*\*Deleting manually configured DC.\n";
        $objDCInst->Delete();
    }
}

This code has been viewed 886 times.

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