Programmatically determine which SQL Server is the primary, what is the mirror?

I am looking for a way to programmatically query which SQL server serves as the main SQL server and which one is the mirror in pair. Does anyone know if this is possible through PowerShell (SQLPS) or CMD (SQLCMD)? If so, how can I request this information?

Thanks in advance!

+5
source share
1 answer

I don't have an instance to test with, but I think you can query sys.database_mirroring_witnesses (SQL Server 2005 or later) using SQLCMD to get the information you are looking for.


@Remus . sys.database_mirroring.

+4

All Articles