Tuesday, September 29, 2015

Remove-SqlAvailabilityDatabase -Path

Been playing a lot with PoSH lately, am now writing a script to automate the restore of a database that's in an availability group. One of the issues I kept running into was getting the correct path for the Remove-SqlAvailabilityDatabase cmdlet. The scripts I'd see online would only have a 'standard' path, like this:

Remove-SqlAvailabilityDatabase `
-Path SQLSERVER:\Sql\SecondaryComputer\InstanceName\AvailabilityGroups\MyAg\Databases\MyDb

Unfortunately that wasn't the path to my DB (and yes, before you say 'did you change the parameters'...yes....yes I did).

So anyways, to make a long story shorter, to find the path to your AG database, open up SSMS, expand AlwaysOn High Availability > Availability Groups > <your group>  and right-click on your database, choosing  Start Powershell. The prompt in the window that opens is the path to your database! So copy that and try the PoSH command Remove-SqlAvailabilityDatabase again and it'll work.

I'll probably post my automated restore solution when I'm done but wanted to get this off my chest.

No comments:

Post a Comment