---
title: "Compare-DbaAgReplicaAgentJob"
description: "Compares SQL Agent Jobs across Availability Group replicas to identify configuration differences."
url: "https://dbatools.io/Compare-DbaAgReplicaAgentJob/"
availability: "Windows, Linux, macOS"
tags: ["AvailabilityGroup", "AG", "Job", "Agent"]
author: "dbatools team"
source: "https://github.com/dataplat/dbatools/blob/master/public/Compare-DbaAgReplicaAgentJob.ps1"
last_updated: "2024-01-01"
---

# Compare-DbaAgReplicaAgentJob

## Synopsis

Compares SQL Agent Jobs across Availability Group replicas to identify configuration differences.

## Description

Compares SQL Agent Jobs across all replicas in an Availability Group to identify differences in job configurations. This helps ensure consistency across AG replicas and detect when jobs have been modified on one replica but not others.  
  
This is particularly useful for verifying that junior DBAs have applied changes to all replicas or for troubleshooting issues where job configurations have drifted between replicas.  
  
By default, compares job names and their presence/absence. Use -IncludeModifiedDate to also compare DateLastModified timestamps to detect configuration drift.

## Syntax

```powershell
Compare-DbaAgReplicaAgentJob
    [[-SqlInstance] <DbaInstanceParameter[]>]
    [[-SqlCredential] <PSCredential>]
    [[-AvailabilityGroup] <String[]>]
    [-ExcludeSystemJob]
    [-IncludeModifiedDate]
    [-EnableException]
    [<CommonParameters>]

```

## Examples

### Example 1: Compares all SQL Agent Jobs across replicas in the AG1 Availability Group

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

### Example 2: Compares user-created SQL Agent Jobs across replicas, excluding system jobs

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

### Example 3: Compares SQL Agent Jobs including their DateLastModified property to detect configuration drift

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

### Example 4: Compares SQL Agent Jobs for all Availability Groups on sql2016 via pipeline input

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

### 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 jobs across their replicas.

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

##### -ExcludeSystemJob

Excludes system jobs from the comparison results.  
Use this to focus on user-created jobs and ignore built-in SQL Server jobs.

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

##### -IncludeModifiedDate

Includes DateLastModified comparison in addition to job name comparison.  
Use this to detect when jobs have been reconfigured on some replicas but not others.

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

##### -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 for each job difference detected across Availability Group replicas. Objects are only returned when differences are found (missing jobs or differing modification dates when -IncludeModifiedDate is specified).

**Properties:**

- AvailabilityGroup: The name of the Availability Group being compared
- Replica: The SQL Server instance name where the job status applies
- JobName: The name of the SQL Agent job
- Status: Job status on this replica (either "Present" or "Missing")
- DateLastModified: DateTime when the job was last modified, or $null if the job is missing on this replica (only populated when -IncludeModifiedDate is specified or job is present)

---

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