commands

^

Set-DbaAgReplica

Author Chrissy LeMaire (@cl), netnerds.net
Availability Windows, Linux, macOS

 

Want to see the source code for this command? Check out Set-DbaAgReplica on GitHub.
Want to see the Bill Of Health for this command? Check out Set-DbaAgReplica.

Synopsis

Sets the properties for a replica to an availability group on a SQL Server instance.

Description

Sets the properties for a replica to an availability group on a SQL Server instance.

Automatically creates a database mirroring endpoint if required.

Syntax

Set-DbaAgReplica
    [[-SqlInstance] <DbaInstanceParameter[]>]
    [[-SqlCredential] <PSCredential>]
    [[-AvailabilityGroup] <String>]
    [[-Replica] <String>]
    [[-AvailabilityMode] <String>]
    [[-FailoverMode] <String>]
    [[-BackupPriority] <Int32>]
    [[-ConnectionModeInPrimaryRole] <String>]
    [[-ConnectionModeInSecondaryRole] <String>]
    [[-SeedingMode] <String>]
    [[-SessionTimeout] <Int32>]
    [[-EndpointUrl] <String>]
    [[-ReadonlyRoutingConnectionUrl] <String>]
    [[-ReadOnlyRoutingList] <Object[]>]
    [[-InputObject] <AvailabilityReplica>]
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Set-DbaAgReplica -SqlInstance sql2016 -Replica sql2016 -AvailabilityGroup SharePoint -BackupPriority 5000

Sets the backup priority to 5000 for the sql2016 replica for the SharePoint availability group on sql2016

Example: 2
PS C:\> Get-DbaAgReplica -SqlInstance sql2016 | Out-GridView -Passthru | Set-DbaAgReplica -BackupPriority 5000

Sets the backup priority to 5000 for the selected availability groups.

Example: 3
PS C:\> Get-DbaAgReplica -SqlInstance sql2016 -Replica Replica1 |
>> Set-DbaAgReplica -ReadOnlyRoutingList Replica2, Replica3

Equivalent to running "ALTER AVAILABILITY GROUP... MODIFY REPLICA... (READ_ONLY_ROUTING_LIST = ('Replica2', 'Replica3'));"

Example: 4
PS C:\> Get-DbaAgReplica -SqlInstance sql2016 -Replica Replica1 |
>> Set-DbaAgReplica -ReadOnlyRoutingList @(,('Replica2','Replica3'));

Equivalent to running "ALTER AVAILABILITY GROUP... MODIFY REPLICA... (READ_ONLY_ROUTING_LIST = (('Replica2', 'Replica3')));" setting a load balanced routing list for when Replica1 is the primary
replica.

Optional Parameters

-SqlInstance

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

Alias
Required False
Pipeline false
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.

Alias
Required False
Pipeline false
Default Value
-AvailabilityGroup

The availability group of the replica.

Alias
Required False
Pipeline false
Default Value
-Replica

The replicas to modify.

Alias
Required False
Pipeline false
Default Value
-AvailabilityMode

Sets the availability mode of the availability group replica. Options are: AsynchronousCommit and SynchronousCommit. SynchronousCommit is default.

Alias
Required False
Pipeline false
Default Value
Accepted Values AsynchronousCommit,SynchronousCommit
-FailoverMode

Sets the failover mode of the availability group replica. Options are Automatic and Manual.

Alias
Required False
Pipeline false
Default Value
Accepted Values Automatic,Manual,External
-BackupPriority

Sets the backup priority availability group replica. Default is 50.

Alias
Required False
Pipeline false
Default Value 0
-ConnectionModeInPrimaryRole

Sets the connection intent modes of an Availability Replica in primary role.

Alias
Required False
Pipeline false
Default Value
Accepted Values AllowAllConnections,AllowReadWriteConnections
-ConnectionModeInSecondaryRole

Sets the connection modes of an Availability Replica in secondary role.

Alias
Required False
Pipeline false
Default Value
Accepted Values AllowAllConnections,AllowNoConnections,AllowReadIntentConnectionsOnly,No,Read-intent only,Yes
-SeedingMode

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.

Alias
Required False
Pipeline false
Default Value
Accepted Values Automatic,Manual
-SessionTimeout

How many seconds an availability replica waits for a ping response from a connected replica before considering the connection to have failed.

Alias
Required False
Pipeline false
Default Value 0
-EndpointUrl

The endpoint URL.

Alias
Required False
Pipeline false
Default Value
-ReadonlyRoutingConnectionUrl

Sets the read only routing connection url for the availability replica.

Alias
Required False
Pipeline false
Default Value
-ReadOnlyRoutingList

Sets the read-only routing list for when this replica is in the primary role.

Alias
Required False
Pipeline false
Default Value
-InputObject

Enables piping from Get-DbaAgReplica.

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

Alias
Required False
Pipeline false
Default Value False
-WhatIf

Shows what would happen if the command were to run. No actions are actually performed.

Alias wi
Required False
Pipeline false
Default Value
-Confirm

Prompts you for confirmation before executing any changing operations within the command.

Alias cf
Required False
Pipeline false
Default Value