Removing Databases from Availability Groups with Powershell

Those days at work I had to remove a bunch of databases from the Availability Groups and later drop them from the primary and secondary replicas. I know I could do the click, click and drop thing, but why not PowerShell?

I decided to invest some time, around 10 minutes and create this nice and small fancy script. I hope that you like!


In the script you can see that I am using the switch –WhatIf, just to show what is going to happen with the execution. Also notice the switch –Script in the Remove-SQLAvailabilityDatabase cmdlet, it will script out the removal of the database, but it will not in fact remove it. Testing the script shows a result like this one below.


The script is located at my GitHub account and you can find the link above.

Let me know if you liked or not the solution Smile Feedback is always appreciated.

Marcos Freccia
Data Platform MVP

About Marcos Freccia

MVP em SQL Server (Data Plataform) , especialista em SQL Server, e atualmente trabalhando com Microsoft Azure!

Posted on February 12, 2018, in Availability Groups, Dicas, GitHub, Powershell, Scripts, VirtualPass and tagged , , , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: