I am looking for a way to programmatically query which SQL server is serving as the principal SQL server and which one is the mirror in a pair. Does anyone know if this is possible via PowerShell (SQLPS) or CMD (SQLCMD)? If so, how can I go about querying this info?
Thanks in advance!
I don't have an instance handy to test with, but I think you should be able to query sys.database_mirroring_witnesses (SQL Server 2005 or later) using SQLCMD to get at the information you are looking for.
EDIT
Thanks to @Remus for the great comment. The appropriate place to look is in sys.database_mirroring
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With