Enum mailboxes (Perl)
This code can be found in
Chapter 6 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 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 script enumerates all the mailboxes in each database in each
# storage group.
# ------ SCRIPT CONFIGURATION ------
use Win32::OLE qw(in);
$strBase = '<LDAP://batman>;';
# <serverName>" ' "batman"
$strComputerName = 'batman';
$strAttrs = 'cn;';
$strScope = 'subtree';
# ------ END CONFIGURATION ---------
$theServer = Win32::OLE->new('CDOEXM.ExchangeServer');
$theSG = Win32::OLE->new('CDOEXM.StorageGroup');
$theConn = Win32::OLE->new('ADODB.Connection');
$theConn->Open('Provider=ADsDSOObject;');
$theServer->DataSource->Open($strComputerName);
# examine the SGs; for each SG, iterate through its databases and
# list the mailboxes in it
foreach my $sg (in $theServer->StorageGroups) {
print 'Storage group ' . chr(34) . $sg . chr(34), "\n";
$theSG->DataSource->open($sg);
$i = 0;
foreach my $mailDB (in $theSG->MailboxStoreDBs) {
$i = $i + 1;
print " Mailbox database $i: $mailDB\n";
print " Users: \n";
$objRS = $theConn->Execute($strBase . '(homeMDB=' . $mailDB . ');' . $strAttrs . $strScope);
$objRS->MoveFirst();
while (!$objRS->EOF) {
print ' ' . $objRS->Fields(0)->Value, "\n";
$objRS->MoveNext();
}
print chr(13) . chr(13), "\n";
}
}
|
This code has been viewed 855 times.
|
New from the creators of TechTasks.com:
StatSheet.com
|