PoshUtils, PowerShell, Scripting, SQL
Leave a comment

PoshUtils: Get all mirrored SQL databases using PowerShell and SMO

I have been validating different aspects of SQL mirroring and in the process I wanted a quick and automated way to handle database mirroring functions. This includes listing all mirrored databases, failing over databases manually to a mirrored instance, etc.

So, in the process, I created several small functions in PowerShell to achieve what I wanted. I will share these functions as a series of posts and eventually, will release a PoshUtils module.

So, in today’s post, let us see how we can retrieve a list of all SQL databases that are mirrored. This function can work with both default and named instances. Also, this assumes that you are using Windows authentication. Let us see the function:

When you run the Get-MirroredDatabase function, it returns a list of all databases that are mirrored and all properties of each database. You can filter the output by selecting the properties you want.

Filed under: PoshUtils, PowerShell, Scripting, SQL

by

Ravikanth is a principal engineer and the lead architect for Microsoft and VMware virtualized and hybrid cloud solutions within the Infrastructure Solutions Group at Dell EMC. He is a multi-year recipient of Microsoft Most Valuable Professional (MVP) award in Windows PowerShell (CDM) and Microsoft Azure. Ravikanth is the author of Windows PowerShell Desired State Configuration Revealed (Apress) and leads Bangalore PowerShell and Bangalore IT Pro user groups. He can be seen speaking regularly at local user group events and conferences in India and abroad.