# 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 creates a new mailbox database at the specified
# location
# ------ SCRIPT CONFIGURATION ------
use Win32::OLE;
$strServerName = '<serverName>';
# e.g. "BATMAN"
$strDBName = '<newMDBName>';
# e.g. "SpiffyNewMDB"
# ------ END CONFIGURATION ---------
$theServer = Win32::OLE->new('CDOEXM.ExchangeServer');
$theMDB = Win32::OLE->new('CDOEXM.MailboxStoreDB');
# bind to the Exchange server and build the database URL
$theServer->DataSource->Open($strServerName);
# Get the array list of StorageGroups and turn it into a
# target SG name. If you want this in another SG, modify
# the code to get the correct one either by name or by index.
$strTemp = $theServer->StorageGroups;
$strTemp1 = VBS::Mid(strTemp(0), (index(strTemp(0), 'CN', 1) + 1));
$theFirstSG = 'CN=' . 'First Storage Group' . ',' . $strTemp1;
$strURL = 'LDAP://' . $theServer->DirectoryServer . '/cn=' . $strDBName . ',' . $theFirstSG;
$theMDB->{Name} = $strDBName;
$theMDB->DataSource->SaveTo($strURL);
print "Created new MDB $strDBName at $strURL\n";
$theMDB->Mount();
print "Mounted new MDB $strDBName\n";
package VBS;
use strict;
sub Mid {
my($substr, $start, $len) = @_;
$start--;
return defined $len ? substr($substr, $start, $len) :
substr($substr, $start);
}
|