Thor Logo dbatools

Compare-DbaAgReplicaSync

View Source
the dbatools team + Claude
Windows, Linux, macOS

Synopsis

Compares server-level objects across Availability Group replicas to identify synchronization differences.

Description

Compares server-level objects across all replicas in an Availability Group to identify differences that would prevent seamless failover. Availability groups only synchronize databases, not the server-level dependencies that applications need to function properly after failover.

This command reports differences without making any changes, making it ideal for monitoring, alerting, and situations where you need to review differences before deciding how to handle them.

By default, compares these object types across all replicas:

SpConfigure
CustomErrors
Credentials
DatabaseMail
LinkedServers
Logins
SystemTriggers
AgentCategory
AgentOperator
AgentAlert
AgentProxy
AgentSchedule
AgentJob

Any of these object types can be excluded using the -Exclude parameter. The command returns structured data showing what objects are missing or different on each replica.

Syntax

Compare-DbaAgReplicaSync
    [[-SqlInstance] <DbaInstanceParameter[]>]
    [[-SqlCredential] <PSCredential>]
    [[-AvailabilityGroup] <String[]>]
    [[-Exclude] <String[]>]
    [-EnableException]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Compare-DbaAgReplicaSync -SqlInstance sql2016 -AvailabilityGroup AG1

Compares all server-level objects across replicas in the AG1 Availability Group and reports differences.

Example: 2
PS C:\> Compare-DbaAgReplicaSync -SqlInstance sql2016 -AvailabilityGroup AG1 -Exclude LinkedServers, DatabaseMail

Compares server-level objects excluding LinkedServers and DatabaseMail configurations.

Example: 3
PS C:\> Get-DbaAvailabilityGroup -SqlInstance sql2016 | Compare-DbaAgReplicaSync

Compares server-level objects for all Availability Groups on sql2016 via pipeline input.

Example: 4
PS C:\> Compare-DbaAgReplicaSync -SqlInstance sql2016 -AvailabilityGroup AG1 | Where-Object Status -eq "Missing"

Shows only objects that are missing on one or more replicas.

Optional Parameters

-SqlInstance

The target SQL Server instance or instances. Can be any replica in the Availability Group.

PropertyValue
Alias
RequiredFalse
Pipelinetrue (ByValue)
Default Value
-SqlCredential

Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported.
For MFA support, please use Connect-DbaInstance.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-AvailabilityGroup

Specifies one or more Availability Group names to compare objects across their replicas.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-Exclude

Excludes specific object types from comparison. Valid values:
SpConfigure, CustomErrors, Credentials, DatabaseMail, LinkedServers, Logins,
SystemTriggers, AgentCategory, AgentOperator, AgentAlert, AgentProxy, AgentSchedule, AgentJob

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
Accepted ValuesAgentCategory,AgentOperator,AgentAlert,AgentProxy,AgentSchedule,AgentJob,Credentials,CustomErrors,DatabaseMail,LinkedServers,Logins,SpConfigure,SystemTriggers
-EnableException

By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with “sea of red” exceptions, but is inconvenient because it basically disables advanced scripting.
Using this switch turns this “nice by default” feature off and enables you to catch exceptions with your own try/catch.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default ValueFalse