Remove-SqlAvailabilityReplica

Removes the secondary availability replica specified by the InputObject or Path parameter.
Remove-SqlAvailabilityReplica [-Path*] <string> [-Script] [-Confirm] [-WhatIf] [<CommonParameters>]
Remove-SqlAvailabilityReplica [-InputObject*] <AvailabilityReplica> [-Script] [-Confirm] [-WhatIf][<CommonParameters>]

The Remove-SqlAvailabilityGroup cmdlet removes the secondary replica specified by the InputObject or Path parameter. This cmdlet can be executed only at the server instance that hosts the primary replica.

Parameters
-InputObject <AvailabilityReplica>

  • This value is required
  • Accepts pipeline input ByValue

The AvailabilityReplica object of the replica that should be removed.

-Path <string>

  • This value is required

The path to the availability replica. This is a mandatory parameter.

-Script [<SwitchParameter>]

Outputs a Transact-SQL script that performs the task executed by this cmdlet.

-Confirm [<SwitchParameter>]

Prompts you for confirmation before executing the command.

-WhatIf [<SwitchParameter>]

Describes what would happen if you executed the command without actually executing the command.

<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,ErrorAction, ErrorVariable, WarningAction, WarningVariable,OutBuffer, PipelineVariable, and OutVariable.

Inputs

Microsoft.SqlServer.Management.Smo.AvailabilityReplica

The availability replica to be removed.

Examples
  1. This command removes the availability replica named ‘MyReplica’ from the availability group named ‘MyAg’:
    C:PS> Remove-SqlAvailabilityReplica -Path SQLSERVER:SQLPrimaryServerInstanceNameAvailabilityGroupsMyAgAvailabilityReplicasMyReplica
    

    This command must be run on the server instance that hosts the primary replica of the availability group.

  2. This command outputs the Transact-SQL script that removes the availability replica named ‘MyReplica’ from the availability group named ‘MyAg’:
    C:PS> Remove-SqlAvailabilityReplica -Path SQLSERVER:SQLPrimaryServerInstanceNameAvailabilityGroupsMyAgAvailabilityReplicasMyReplica -Script
    

    The replica is not actually removed by this command.

Additional Notes