List Exchange servers (Perl)

This code can be found in Chapter 2 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 uses WMI to interrogate the Exchange routing table 
# and list all known Exchange servers.
# ------ SCRIPT CONFIGURATION ------

use Win32::OLE qw(in);

$strComputerName = 'batman';
# e.g. "batman.robichaux.net"

# ------ END CONFIGURATION ---------
$strE2KWMIQuery = 'winmgmts://' . $strComputerName . '/root/cimv2/applications/exchange';
$strE2K3WMIQuery = 'winmgmts://' . $strComputerName . '/root/MicrosoftExchangeV2';

# display basic attributes using Exchange 2000 WMI provider 
$serverList = Win32::OLE->GetObject('ExchangeServerState');
print "Exchange 2000/Exchange Server 2003 properties\n";
foreach my $ExchangeServer (in $serverList) {
    print '  Name:    ' . $ExchangeServer->Name, "\n";
    print '  DN:      ' . $ExchangeServer->GroupDN, "\n";
    print '  Version: ' . $ExchangeServer->Version, "\n";
}
print "\n";

# display additional Exchange 2003 provider information
$serverList = Win32::OLE->GetObject('Exchange_Server');
print "Exchange Server 2003 properties\n";
foreach my $Exchange_Server (in $serverList) {
    print "Exchange 2003 properties--------\n";
    print '  Name:        ' . $Exchange_Server->Name, "\n";
    print '  FQDN:        ' . $Exchange_Server->FQDN, "\n";
    print '  Admin Group  ' . $Exchange_Server->AdministrativeGroup, "\n";
}

This code has been viewed 1509 times.

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