#PSTip List SQL database mirroring partner using SMO

Note: This tip requires PowerShell 2.0 or above.

In an earlier tip, we looked at how to verify if a SQL database is mirrored. Continuing this series on SQL SMO tips series, let us look at how we can list the SQL database mirroring partner information. I find this information quite helpful when managing the SQL Server mirroring. The database class in SQL SMO has a property called MirroringPartner. This provides us the information of the Database Engine instance that is the partner server for database mirroring.

Add-Type -AssemblyName "Microsoft.SqlServer.Smo, Version=, Culture=neutral, PublicKeyToken=89845dcd8080cc91"
$smo = New-Object Microsoft.SqlServer.Management.Smo.Server $env:COMPUTERNAME

The above code snippet returns the mirroring partner FQDN along with the TCP port number. In case you need only the name of the SQL Server instance hosting the mirroring partner, you can use the following code.

Share on: