List Storage Group (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 lists all of the storage groups on the specified server.
# For each SG, it lists information on the SG, including its
# database stores and their paths.

# ------ SCRIPT CONFIGURATION ------

use Win32::OLE qw(in);

$strComputerName = '<serverName>';
# e.g. "batman"
# ------ END CONFIGURATION ---------

$theServer = Win32::OLE->new('CDOEXM.ExchangeServer');
$theSG = Win32::OLE->new('CDOEXM.StorageGroup');
$thePF = Win32::OLE->new('CDOEXM.PublicStoreDB');
$theMB = Win32::OLE->new('CDOEXM.MailboxStoreDB');

$theServer->DataSource->Open($strComputerName);

# examine the SGs; for each SG, list its associated stores and paths
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";
        $theMB->DataSource->open($mailDB);
        print '                     Name:' . $theMB->name, "\n";
        print '                     Path:' . $theMB->DBPath, "\n";
    }
    $i = 0;
    foreach my $pubDB (in $theSG->PublicStoreDBs) {
        $i = $i + 1;
        print "       PF database $i: $mailDB\n";
        $thePF->DataSource->open($pubDB);
        print '                     Name:' . $thePF->Name, "\n";
        print '                     Path:' . $thePF->DBPath, "\n";
    }

}

This code has been viewed 924 times.

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