< Back
Add-DbaAgReplica
Post
NAME Add-DbaAgReplica
SYNOPSIS
Adds a replica to an availability group on a SQL Server instance.
SYNTAX
Add-DbaAgReplica [[-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>] [[-SqlCredential]
<Pscredential>] [[-Name] <String>] [[-AvailabilityMode] <String>] [[-FailoverMode] <String>] [[-BackupPriority]
<Int>] [[-ConnectionModeInPrimaryRole] <String>] [[-ConnectionModeInSecondaryRole] <String>] [[-SeedingMode]
<String>] [[-Endpoint] <String>] [-Passthru <Switch>] [[-ReadonlyRoutingConnectionUrl] <String>] [[-Certificate]
<String>] [-InputObject] <Microsoft.SqlServer.Management.Smo.AvailabilityGroup> [-EnableException <Switch>]
[<CommonParameters>]
DESCRIPTION
Adds a replica to an availability group on a SQL Server instance.
Automatically creates a database mirroring endpoint if required.
PARAMETERS
-AvailabilityMode [<String>]
Sets the availability mode of the availability group replica. Options are: AsynchronousCommit and
SynchronousCommit. SynchronousCommit is default.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-BackupPriority [<Int>]
Sets the backup priority availability group replica. Default is 50.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Certificate [<String>]
Specifies that the endpoint is to authenticate the connection using the certificate specified by
certificate_name to establish identity for authorization.
The far endpoint must have a certificate with the public key matching the private key of the specified
certificate.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-ConnectionModeInPrimaryRole [<String>]
Specifies the connection intent modes of an Availability Replica in primary role. AllowAllConnections by
default.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-ConnectionModeInSecondaryRole [<String>]
Specifies the connection modes of an Availability Replica in secondary role. AllowAllConnections by default.
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
-Endpoint [<String>]
By default, this command will attempt to find a DatabaseMirror endpoint. If one does not exist, it will create
it.
If an endpoint must be created, the name "hadr_endpoint" will be used. If an alternative is preferred, use
Endpoint.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-FailoverMode [<String>]
Sets the failover mode of the availability group replica. Options are Automatic and Manual. Automatic is
default.
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
-Name [<String>]
The name of the replica. Defaults to the SQL Server instance name.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Passthru [<Switch>]
Don't create the replica, just pass thru an object that can be further customized before creation.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-ReadonlyRoutingConnectionUrl [<String>]
Sets the read only routing connection url for the availability replica.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SeedingMode [<String>]
Specifies how the secondary replica will be initially seeded.
Automatic enables direct seeding. This method will seed the secondary replica over the network. This method
does not require you to backup and restore a copy of the primary database on the replica.
Manual requires you to create a backup of the database on the primary replica and manually restore that backup
on the secondary replica.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SqlCredential [<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
-SqlInstance [<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
<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:\\>Get-DbaAvailabilityGroup -SqlInstance sql2017a -AvailabilityGroup SharePoint | Add-DbaAgReplica
-SqlInstance sql2017b
Adds sql2017b to the SharePoint availability group on sql2017a
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Get-DbaAvailabilityGroup -SqlInstance sql2017a -AvailabilityGroup SharePoint | Add-DbaAgReplica
-SqlInstance sql2017b -FailoverMode Manual
Adds sql2017b to the SharePoint availability group on sql2017a with a manual failover mode.
RELATED LINKS
https://dbatools.io/Add-DbaAgReplica
SYNOPSIS
Adds a replica to an availability group on a SQL Server instance.
SYNTAX
Add-DbaAgReplica [[-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>] [[-SqlCredential]
<Pscredential>] [[-Name] <String>] [[-AvailabilityMode] <String>] [[-FailoverMode] <String>] [[-BackupPriority]
<Int>] [[-ConnectionModeInPrimaryRole] <String>] [[-ConnectionModeInSecondaryRole] <String>] [[-SeedingMode]
<String>] [[-Endpoint] <String>] [-Passthru <Switch>] [[-ReadonlyRoutingConnectionUrl] <String>] [[-Certificate]
<String>] [-InputObject] <Microsoft.SqlServer.Management.Smo.AvailabilityGroup> [-EnableException <Switch>]
[<CommonParameters>]
DESCRIPTION
Adds a replica to an availability group on a SQL Server instance.
Automatically creates a database mirroring endpoint if required.
PARAMETERS
-AvailabilityMode [<String>]
Sets the availability mode of the availability group replica. Options are: AsynchronousCommit and
SynchronousCommit. SynchronousCommit is default.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-BackupPriority [<Int>]
Sets the backup priority availability group replica. Default is 50.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Certificate [<String>]
Specifies that the endpoint is to authenticate the connection using the certificate specified by
certificate_name to establish identity for authorization.
The far endpoint must have a certificate with the public key matching the private key of the specified
certificate.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-ConnectionModeInPrimaryRole [<String>]
Specifies the connection intent modes of an Availability Replica in primary role. AllowAllConnections by
default.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-ConnectionModeInSecondaryRole [<String>]
Specifies the connection modes of an Availability Replica in secondary role. AllowAllConnections by default.
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
-Endpoint [<String>]
By default, this command will attempt to find a DatabaseMirror endpoint. If one does not exist, it will create
it.
If an endpoint must be created, the name "hadr_endpoint" will be used. If an alternative is preferred, use
Endpoint.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-FailoverMode [<String>]
Sets the failover mode of the availability group replica. Options are Automatic and Manual. Automatic is
default.
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
-Name [<String>]
The name of the replica. Defaults to the SQL Server instance name.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Passthru [<Switch>]
Don't create the replica, just pass thru an object that can be further customized before creation.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-ReadonlyRoutingConnectionUrl [<String>]
Sets the read only routing connection url for the availability replica.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SeedingMode [<String>]
Specifies how the secondary replica will be initially seeded.
Automatic enables direct seeding. This method will seed the secondary replica over the network. This method
does not require you to backup and restore a copy of the primary database on the replica.
Manual requires you to create a backup of the database on the primary replica and manually restore that backup
on the secondary replica.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SqlCredential [<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
-SqlInstance [<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
<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:\\>Get-DbaAvailabilityGroup -SqlInstance sql2017a -AvailabilityGroup SharePoint | Add-DbaAgReplica
-SqlInstance sql2017b
Adds sql2017b to the SharePoint availability group on sql2017a
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Get-DbaAvailabilityGroup -SqlInstance sql2017a -AvailabilityGroup SharePoint | Add-DbaAgReplica
-SqlInstance sql2017b -FailoverMode Manual
Adds sql2017b to the SharePoint availability group on sql2017a with a manual failover mode.
RELATED LINKS
https://dbatools.io/Add-DbaAgReplica