< Back

Sync-DbaAvailabilityGroup

Mon Jan 13, 2020 5:58 pm

NAME Sync-DbaAvailabilityGroup



SYNOPSIS

Syncs dependent objects such as jobs, logins and custom errors for availability groups





SYNTAX

Sync-DbaAvailabilityGroup [[-Primary] <DbaInstanceParameter>] [[-PrimarySqlCredential] <Pscredential>]

[[-Secondary] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>] [[-SecondarySqlCredential]

<Pscredential>] [[-AvailabilityGroup] <String>] [[-Exclude] <System.String[]>] [[-Login] <System.String[]>]

[[-ExcludeLogin] <System.String[]>] [[-Job] <System.String[]>] [[-ExcludeJob] <System.String[]>] [[-InputObject]

<Microsoft.SqlServer.Management.Smo.AvailabilityGroup[]>] [-Force <Switch>] [-EnableException <Switch>]

[<CommonParameters>]





DESCRIPTION

Syncs dependent objects for availability groups. Such objects include:



SpConfigure



CustomErrors



Credentials



DatabaseMail



LinkedServers



Logins



LoginPermissions



SystemTriggers



DatabaseOwner



AgentCategory



AgentOperator



AgentAlert



AgentProxy



AgentSchedule



AgentJob



Note that any of these can be excluded. For specific object exclusions (such as a single job), using the

underlying Copy-Dba* command will be required.



This command does not filter by which logins are in use by the ag databases or which linked servers are used. All

objects that are not excluded will be copied like hulk smash.





PARAMETERS

-AvailabilityGroup [<String>]

The name of the Availability Group.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-EnableException [<Switch>]

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.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Exclude [<System.String[]>]

Exclude one or more objects to export



SpConfigure

CustomErrors

Credentials

DatabaseMail

LinkedServers

Logins

LoginPermissions

SystemTriggers

DatabaseOwner

AgentCategory

AgentOperator

AgentAlert

AgentProxy

AgentSchedule

AgentJob



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-ExcludeJob [<System.String[]>]

Specific jobs to exclude when performing the sync. If unspecified, all jobs will be processed.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-ExcludeLogin [<System.String[]>]

Specific logins to exclude when performing the sync. If unspecified, all logins will be processed.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Force [<Switch>]

If this switch is enabled, the objects will dropped and recreated on Destination.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-InputObject [<Microsoft.SqlServer.Management.Smo.AvailabilityGroup[]>]

Enables piping from Get-DbaAvailabilityGroup.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Job [<System.String[]>]

Specific jobs to sync. If unspecified, all jobs will be processed.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Login [<System.String[]>]

Specific logins to sync. If unspecified, all logins will be processed.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Primary [<DbaInstanceParameter>]

The primary SQL Server instance. Server version must be SQL Server version 2012 or higher.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-PrimarySqlCredential [<Pscredential>]

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.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Secondary [<Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>]

The target SQL Server instance or instances. Server version must be SQL Server version 2012 or higher.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SecondarySqlCredential [<Pscredential>]

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.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



NOTES





Tags: AvailabilityGroup, HA, AG

Author: Chrissy LeMaire (@cl), netnerds.net



Website: https://dbatools.io

Copyright: (c) 2018 by dbatools, licensed under MIT

License: MIT https://opensource.org/licenses/MIT



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>Sync-DbaAvailabilityGroup -Primary sql2016a -AvailabilityGroup db3



Syncs the following on all replicas found in the db3 AG:

SpConfigure, CustomErrors, Credentials, DatabaseMail, LinkedServers

Logins, LoginPermissions, SystemTriggers, DatabaseOwner, AgentCategory,

AgentOperator, AgentAlert, AgentProxy, AgentSchedule, AgentJob

-------------------------- EXAMPLE 2 --------------------------



PS C:\\>Get-DbaAvailabilityGroup -SqlInstance sql2016a | Sync-DbaAvailabilityGroup -ExcludeType LoginPermissions,

LinkedServers -ExcludeLogin login1, login2 -Job job1, job2



Syncs the following on all replicas found in all AGs on the specified instance:

SpConfigure, CustomErrors, Credentials, DatabaseMail, Logins,

SystemTriggers, DatabaseOwner, AgentCategory, AgentOperator

AgentAlert, AgentProxy, AgentSchedule, AgentJob.



Copies all logins except for login1 and login2 and only syncs job1 and job2

-------------------------- EXAMPLE 3 --------------------------



PS C:\\>Get-DbaAvailabilityGroup -SqlInstance sql2016a | Sync-DbaAvailabilityGroup -WhatIf



Shows what would happen if the command were to run but doesn't actually perform the action.



RELATED LINKS

https://dbatools.io/Sync-DbaAvailabilityGroup