Friday, October 8, 2010

Bulk Create Exchange 2010 Databases

By:Rik Hoffelder


Here's a handy script I wrote to bulk create mailbox databases to follow a strict naming convention and consistent configuration. It was designed to work with Exchange 2010, however it works just as well with 2007. The intent is to help organizations maintain consistency using a simple process that can be performed by less skilled administrators.


Script itself uses several command line parameters to create the variables needed for the scripts. The following provides the script usage:


.\createdbs.ps1 2010Server NumberOfDatabases DatabaseStartNumber DatabaseDrive LogDrive WarningQuota SendQuota SendReceiveQuota DeletedItemRetention MailboxRetention Oab PfDb

The following is an example of proper usage:

.\CreateDbs.PS1 EX2010 4 1 E D 450MB 500MB Unlimited 30 14 "\Default Offline Address List" "Public Folder Database 1"

In the above example 4 databases are created on server EX2010 with the following names:

EX2010-DB01-0500
EX2010-DB02-0500
EX2010-DB03-0500
EX2010-DB04-0500

The database are created on drive E, with the log files on drive D. The mailbox store is set to issue size limit warnings at 450MB, prohibit send at 500MB, and prohibit send/receive is set to unlimited. Next deleted items are retained for 30 days, while deleted mailboxes are retained for 14. Finally the Offline Address book is set along with the public folder database used by each mailbox store.

So let's suppose we need to create 3 more databases, but this time on drive G, with the logs on drive H. Let's also set the mailbox size limit to 1GB. You would run the following:

.\CreateDbs.PS1 EX2010 3 5 G H 900MB 1GB 2GB 10 7 "\North America OAB" "Public Folder Database 2"

This would have created databases EX2010-DB05-1000, EX2010-DB06-1000, and EX2010-DB07-1000 with 10 day deleted item retention, 7 day delete mailbox retention, a warning limit of 900MB, prohibit send at 1GB and prohibit send/receive at 2 GB. The OAB would be set to North America OAB and use Public Folder Database 2.

Notice how the DBxx value began with DB05 and the last four digits are now 1000.
The DbStartNum parameter determine the beginning of the numbering scheme in the DBxx portion. The -XXXX at the end uses the ProhibitSend value to represent the mailbox send size limit, making it easy for administrators to identify where to place mailboxes by the database name. A size limit of 125MB would produce a name SERVER-DBXX-0125 and so forth.

It's simple and flexible. To run it simply copy it to a PS1 file then lanuch it from Exchange Management Shell.

CreateDatabases.PS1

### BEGIN SCRIPT ###
Param(
[string] $2010Server = "",
[decimal] $NumDatabases = "",
[decimal] $DbStartNum = "",
[string] $DbDrive = "",
[string] $LogDrive = "",
[string] $WarnQuota = "",
[string] $SendQuota = "",
[string] $SendReceiveQuota = "",
[string] $DeletedItemRetention = "",
[string] $MailboxRetention = "",
[string] $OAB = "",
[string] $PfDb = ""
)

# This function validates the scripts parameters
function ValidateParams
{
$validInputs = $true
$errorString = ""
if ($2010Server -eq "")
{
$validInputs = $false
$errorString += "`nMissing parameter: The 2010Server parameter is required. Please enter the name of the Exchange 2010 server to configure. Example KCCEX2010"
}
if ($NumDatabases -eq "")
{
$validInputs = $false
$errorString += "`nMissing parameter: The NumDatabases parameter is required. Please enter the number of mailbox databases that will be created on this Exchange 2010 server. Example 8."
}
if ($DbStartNum -eq "")
{
$validInputs = $false
$errorString += "`nMissing parameter: The DbStartNum parameter is required. Please enter the starting database number. Example 5."
}
if ($DbDrive -eq "")
{
$validInputs = $false
$errorString += "`nMissing parameter: The DbDrive parameter is required. Please enter the drive letter on which you will create mailbox databases. Example: E"
}
if ($LogDrive -eq "")
{
$validInputs = $false
$errorString += "`nMissing parameter: The LogDrive parameter is required. Please enter the drive letter on which you will create transaction logs. Example: D"
}
if ($WarnQuota -eq "")
{
$validInputs = $false
$errorString += "`nMissing parameter: The WarnQuota parameter is required. Please enter the vaule to issue mailbox size limit warning. Example: 450MB or 1.5GB"
}
if ($SendQuota -eq "")
{
$validInputs = $false
$errorString += "`nMissing parameter: The SendQuota parameter is required. Please enter the vaule to issue mailbox size limit exceeded. Example: 500MB or 1GB"
}
if ($SendReceiveQuota -eq "")
{
$validInputs = $false
$errorString += "`nMissing parameter: The SendReceiveQuota parameter is required. Please enter the vaule at which the mailbox stops accepting mail. Example: Unlimited or 550MB"
}

if ($DeletedItemRetention -eq "")
{
$validInputs = $false
$errorString += "`nMissing parameter: The DeletedItemRetention parameter is required. Please enter the vaule in days. Example: 14"
}
if ($MailboxRetention -eq "")
{
$validInputs = $false
$errorString += "`nMissing parameter: The MailboxRetention parameter is required. Please enter the vaule in days. Example: 30"
}
if ($OAB -eq "")
{
$validInputs = $false
$errorString += "`nMissing parameter: The OAB parameter is required. Please enter the name of the offline address list to be used by this mailbox database in quotes. Example: 'Corporate OAB' "
}
if ($PfDb -eq "")
{
$validInputs = $false
$errorString += "`nMissing parameter: The PfDb parameter is required. Please enter the name of the public folder database in quotes. Example: 'Pub Folders DB 1'"
}

if (!$validInputs)
{
Write-error "$errorString"
}
return $validInputs
}


### Validate the parameters ###
$ifValidParams = ValidateParams;

if (!$ifValidParams) { exit; }

### Define Script variables ###
$2010Server = $2010Server.ToUpper()
$b = $NumDatabases + $DbStartNum
$DeletedItemRetention = $DeletedItemRetention + ".00:00:00"
$MailboxRetention = $MailboxRetention + ".00:00:00"

$SendQuotaLen = $SendQuota.Length
$DBSize = $SendQuotaLen - 2
[decimal] $DBSizeNum = $SendQuota.substring(0,$DBSize)

If ($DbSizeNum -le 9) {$DbExName = [string] $DbSizeNum + "000"}
ElseIf ($DbSizeNum -ge 10 -and $DbSizeNum -le 99) {$DbExName = "00" + $DbSizeNum}
ElseIf ($DbSizeNum -ge 100) {$DbExName = "0" + $DbSizeNum}

If ($DbStartNum -gt 9) {$MdbName = $2010Server + "-DB" + $DbStartNum + "-" + $DbExName}
Else {$MdbName = $2010Server + "-DB0" + $DbStartNum + "-" + $DbExName}
$EdbFilePath = $DbDrive + ":\Exchange\Databases\" + $MdbName + "\" + $MdbName + ".EDB"
$LogFolderPath = $LogDrive + ":\Exchange\Logs\" + $MdbName
$MdbID = $2010Server + "\" + $MdbName

### Create Mailbox Databases Loop ###
Do {New-MailboxDatabase -Name $MdbName -Server $2010Server -EdbFilePath $EdbFilePath -LogFolderPath $LogFolderPath -OfflineAddressBook $OAB -PublicFolderDatabase $PfDb
;Mount-Database $MdbName
;Set-MailboxDatabase –Identity $MdbName –IssueWarningQuota $WarnQuota –ProhibitSendQuota $Sendquota –ProhibitSendReceiveQuota $SendReceiveQuota -DeletedItemRetention $DeletedItemRetention -MailboxRetention $MailboxRetention -RetainDeletedItemsUntilBackup $True
;$DbStartNum++
;If ($DbStartNum -gt 9) {$MdbName = $2010Server + "-DB" + $DbStartNum + "-" + $DbExName}
Else {$MdbName = $2010Server + "-DB0" + $DbStartNum + "-" + $DbExName}
;$EdbFilePath = $DbDrive + ":\Exchange\Databases\" + $MdbName + "\" + $MdbName + ".EDB"
;$LogFolderPath = $LogDrive + ":\Exchange\Logs\" + $MdbName
;$MdbID = $2010Server + "\" + $MdbName
}
Until ($DbStartNum -eq $b)
### END SCRIPT ###






More information on Exchange



11 comments:

  1. This truly is a very important blog. Thanks for sharing this valuable information with us.

    ReplyDelete
  2. Thanks for sharing this valuable information with us.

    ReplyDelete
  3. This has been a very significant blog indeed. I’ve acquired a lot of helpful information from your article. Thank you for sharing such relevant topic with us. I really love all the great stuff you provide. Thanks again and keep it coming

    ReplyDelete
  4. Thank you for sharing such relevant topic with us. I really love all the great stuff you provide. Thanks again and keep it coming

    ReplyDelete
  5. You made a huge effort to express all that information so shortly in order to make it more comprehensive. Thanks a lot for giving us these useful tips and advice.

    ReplyDelete
  6. Like the other databases, Exchange database may also faces the issues of corruption and does not allow you to perform any activity. Generally there are two types of database corruption in Exchange server, called Physical and Logical. The Physical corruption occurs due to a hardware problem and usually damage the data on drive. The logical database corruption is very common and appears due to internal fault in the database. When it occurs, exchange database file becomes totally unusable and you can experience serious data loss. Microsoft Exchange Server has included some utilities to detect and fix the logical database corruption problem. However, these tools have limited features and fails to give fruitful results in case of severe database corruption. In this situation, you need to opt for a third party Exchange Server recovery software to get your precious data back.

    ReplyDelete
  7. thanks for the info about Exchange Databases, really helpful!

    ReplyDelete
  8. To repair and rebuild the damaged or failed Exchange Server 2010 or any other version, you can use ESEUTIL tools. But due to some shortcomings, these inbuilt utilities do not work. In such case a third party Exchange database recovery software can efficiently help you to repair and rebuild the MS Exchange Server.

    thanks
    James

    ReplyDelete
  9. Thanks for sharing the useful information. Recovering data from corrupt exchange database is not so easy. However, I have also explored a very informative resource which provide complete and effective solution for exchange disaster recovery, backup restoration as well as exchange server migration without undergone lengthy process. One can go through further given link to check more details : http://www.petri.co.il/edbtopst.htm

    ReplyDelete
  10. To repair the corrupt or damaged exchange server of any version try SysInfoTools Software https://www.sysinfotools.com

    ReplyDelete

Microsoft Virtualization, Citrix, XENServer, Storage, iscsi, Exchange, Virtual Desktops, XENDesktop, APPSense, Netscaler, Virtual Storage, VM, Unified Comminications, Cisco, Server Virtualization, Thin client, Server Based Computing, SBC, Application Delivery controllers, System Center, SCCM, SCVMM, SCOM, VMware, VSphere, Virtual Storage, Cloud Computing, Provisioning Server, Hypervisor, Client Hypervisor.