Check Mirroring Status with Powershell

Here’s a simple Powershell snippet to check the mirroring status on your SQL Server instances.

?View Code POWERSHELL
# Load SMO extension
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") | Out-Null;
 
# Servers to check
$sqlservers = @("server1", "server2", "server3");
foreach($server in $sqlservers)
{
	$srv = New-Object "Microsoft.SqlServer.Management.Smo.Server" $server;
	# Get mirrored databases
	$databases = $srv.Databases | Where-Object {$_.IsMirroringEnabled -eq $true}; 
	Write-Host $server;
	Write-Host "==================================";
	$databases | Select-Object -Property Name, MirroringStatus | Format-Table -AutoSize;
}

This will output something looking like below…

server1
====================================

Name                 MirroringStatus
----                 ---------------
db1         		Synchronized
db2                    	Synchronized
db3              	Synchronized
db4			Synchronized
db5    			Synchronized
server2
=====================================

Name                 MirroringStatus
----                 ---------------
db1         		Synchronized
db2                    	Synchronized
db3              	Synchronized
db4			Synchronized
db5    			Synchronized
server3
=====================================

Name                 MirroringStatus
----                 ---------------
db1         		Synchronized
db2                    	Synchronized
db3              	Synchronized
db4			Synchronized
db5    			Synchronized

Leave a Reply