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.