#PSTip Verify if a SQL database is mirrored or not

Note: This tip requires PowerShell 2.0 or above.

When using SQL SMO to work with mirroring configuration, it is essential to verify if the database is mirrored, or not, before performing any other operations. In today’s tip, we shall see how to use SQL SMO in PowerShell to achieve this.

Add-Type -AssemblyName "Microsoft.SqlServer.Smo, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"
$smo = New-Object Microsoft.SqlServer.Management.Smo.Server $env:COMPUTERNAME
$smo.Databases['MyDB'].IsMirroringEnabled

The IsMirroringEnabled property returns a boolean value that specifies whether mirroring is enabled on the database. If True, the database has mirroring enabled. Otherwise, False is returned.

Share on:
comments powered by Disqus