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.

, ,

About Author

about author

Josh Bryant

Josh M. Bryant is currently a Senior Director of Technical Account Management at Tanium where he helps customers overcome the challenges of managing very large scale computing environments. Prior to joining Tanium, he was a Premier Field Engineer at Microsoft specializing in Microsoft Exchange Server, and then later a Cybersecurity Architect specializing in Compromise Recovery. Josh is also a Master Sergeant in the Illinois Air National Guard where he manages a team of Cyber Threat Intelligence specialists.

Leave a Reply

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