Exchange 2010: Database Copies with PowerShell

By: Justin Braun
Posted on: December 9, 2009

I needed a quick and dirty method to add database copies to other servers in an Exchange 2010 Database Availability Group (DAG).  I had three servers, each with 10 databases.  Each one of those databases should have a copy on the other two servers. 

Now, this is painful if you have to use the GUI to do it – not that it takes a lot, but it’s time consuming.  The Add-MailboxDatabaseCopy cmdlet is very helpful in PowerShell, but still I wanted to automate it since my naming conventions were pretty standard.

So, I wrote a PowerShell script to automate this process.  Essentially, the script has a few variables and I dome some loop magic to drop everything into place. 

$servers = "E2K10MBX01", "E2K10MBX02", "E2K10MBX03"
$databases = "DB1", "DB2", "DB3", "DB4", "DB5", "DB6", "DB7", "DB8", "DB9", "DB10"
 
foreach($database in $databases)
{
       foreach($server in $servers)
       {
              foreach($copyserver in $servers)
              {
                     "Adding mailbox copy for $server-$database to $copyserver..."
                     Add-MailboxDatabaseCopy -Identity $server-$database -MailboxServer $copyserver -ErrorAction "Continue"
              }
       }
}

This script is quick and dirty for a lab environment.  Keep in mind that this doesn’t do any error checking and there is no validation to see if a database is already homed to a server.  This just uses the cmdlet to try to create the database copy; if it is successful, you’re good to go.  If it fails, the script just keeps on rolling.  No harm, no foul.

Related Articles

Quick Hit: Export-Mailbox Cmdlet in Exchange 2007

Ever needed to export the contents of an entire mailbox (or mailboxes)?  The Export-Mailbox cmd

PowerShell with Compellent and Exchange 2010

I’ve been doing lots of work in the lab lately with Exchange 2010 to understand all the new change

Checking Partition Alignment with PowerShell

Here is an easy way to determine the partition alignment of any given disk on the local system or remotely.