Mass deletion of databases on an Exchange 2010 Database Availability Group.

Last week I showed you a script that I wrote to create a mass amount of databases and database copies on an Exchange 2010 Database Availability Group (DAG).   Since that script was a work in progress, I needed to test it again.  This meant I needed to get rid of most of the databases it created the first time I ran it.  To do this, I used the same .csv file to create the databases, and just removed the databases from the list that I didn't want deleted.   Then I ran this script I called rmdb.ps1:

# Remove Databases
# By Josh M. Bryant
$data = Import-CSV C:\Scripts\dbcreate\exdbs.csv
$Servers = Get-MailboxServer | Where {$_.DatabaseAvailabilityGroup -ne $null}
ForEach ($line in $data)
$dbname = $line.DBName
    ForEach($Server in $Servers)
    Remove-MailboxDatabaseCopy -Identity $dbname\$Server -Confirm:$False
Remove-MailboxDatabase -Identity $dbname -Confirm:$false


On an Exchange 2010 DAG, you have to delete all copies of the database BEFORE it will allow you to delete the database.  The GUI will only allow you to do this one at a time, so if you've got a large number of databases that need deleting, this script is a real time saver.  Database copies and databases are deleted much faster than they're created.

Leave a Reply

Your email address will not be published. Required fields are marked *