---
title: "Compare-DbaAgReplicaSync"
description: "Compares server-level objects across Availability Group replicas to identify synchronization differences."
url: "https://dbatools.io/Compare-DbaAgReplicaSync/"
availability: "Windows, Linux, macOS"
tags: ["AvailabilityGroup", "AG", "Sync", "Compare"]
author: "the dbatools team + Claude"
source: "https://github.com/dataplat/dbatools/blob/master/public/Compare-DbaAgReplicaSync.ps1"
last_updated: "2024-01-01"
---

# Compare-DbaAgReplicaSync

## 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

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

```

## Examples

### Example 1: Compares all server-level objects across replicas in the AG1 Availability Group and reports differences

```powershell
PS C:\> Compare-DbaAgReplicaSync -SqlInstance sql2016 -AvailabilityGroup AG1
```

### Example 2: Compares server-level objects excluding LinkedServers and DatabaseMail configurations

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

### Example 3: Compares server-level objects for all Availability Groups on sql2016 via pipeline input

```powershell
PS C:\> Get-DbaAvailabilityGroup -SqlInstance sql2016 | Compare-DbaAgReplicaSync
```

### Example 4: Shows only objects that are missing on one or more replicas

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

### Optional Parameters

##### -SqlInstance

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

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | true (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.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -AvailabilityGroup

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

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -Exclude

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

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |
| Accepted Values | AgentCategory,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.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value | False |

## Outputs

**PSCustomObject**

Returns one object per difference detected across the Availability Group replicas. Each object represents a synchronization discrepancy that would impact failover readiness.

**Properties:**

- AvailabilityGroup: Name of the Availability Group being compared
- Replica: Name of the replica where the discrepancy was detected
- ObjectType: Type of object with the difference (Login, AgentJob, Credential, LinkedServer, AgentOperator, AgentAlert, AgentProxy, CustomError)
- ObjectName: Name of the specific object that differs
- Status: Current state of the object ("Missing" when object exists on another replica but not this one, "Different" when object exists but has different configuration)
- PropertyDifferences: String containing details of property differences (populated only for Login objects when Status is "Different"; null for other object types or when Status is "Missing")

---

Part of [dbatools](https://dbatools.io/), a free and open source PowerShell module for SQL Server administration. Full command index: https://dbatools.io/commands/
