Search Active Directory for 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 searches Active Directory for Exchange servers
# ------ SCRIPT CONFIGURATION ------

use Win32::OLE;

$strBase = '<LDAP://cn=microsoft exchange,cn=services,cn=configuration,dc=<domain>,dc=<TLD>;';
# e.g. " dc=robichaux, dc=net"
# ------ END CONFIGURATION ---------

$strFilter = '(objectCategory=msExchExchangeServer);';
$strAttrs = 'cn;';
$strScope = 'subtree';

$objConn = Win32::OLE->new('ADODB.Connection');
$objConn->Open('Provider=ADsDSOObject;');

$objRS = $objConn->Execute($strBase . $strFilter . $strAttrs . $strScope);
$objRS->MoveFirst();
while (!$objRS->EOF) {
    print $objRS->Fields(0)->Value, "\n";
    $objRS->MoveNext();
}

This code has been viewed 930 times.

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