Compare-DbaAgReplicaAgentJob
View SourceSynopsis
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
Compare-DbaAgReplicaAgentJob
[[-SqlInstance] <DbaInstanceParameter[]>]
[[-SqlCredential] <PSCredential>]
[[-AvailabilityGroup] <String[]>]
[-ExcludeSystemJob]
[-IncludeModifiedDate]
[-EnableException]
[<CommonParameters>]
Examples
Example: 1
PS C:\> Compare-DbaAgReplicaAgentJob -SqlInstance sql2016 -AvailabilityGroup AG1
Compares all SQL Agent Jobs across replicas in the AG1 Availability Group.
Example: 2
PS C:\> Compare-DbaAgReplicaAgentJob -SqlInstance sql2016 -AvailabilityGroup AG1 -ExcludeSystemJob
Compares user-created SQL Agent Jobs across replicas, excluding system jobs.
Example: 3
PS C:\> Compare-DbaAgReplicaAgentJob -SqlInstance sql2016 -AvailabilityGroup AG1 -IncludeModifiedDate
Compares SQL Agent Jobs including their DateLastModified property to detect configuration drift.
Example: 4
PS C:\> Get-DbaAvailabilityGroup -SqlInstance sql2016 | Compare-DbaAgReplicaAgentJob
Compares SQL Agent Jobs for all Availability Groups on sql2016 via pipeline input.
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 |
dbatools