Join-SqlAvailabilityGroup

Joins the availability replica specified in the InputObject or Path parameter to the availability group specifiedby the Name parameter.
Join-SqlAvailabilityGroup [[-Path] <string>] -Name* <string> [-Script] [-Confirm] [-WhatIf] [<CommonParameters>]
Join-SqlAvailabilityGroup [-InputObject*] <Server> -Name* <string> [-Script] [-Confirm] [-WhatIf][<CommonParameters>]

The Join-SqlAvailabilityGroup cmdlet joins the local secondary replica to the availability group that is specified in the Name parameter. This cmdlet can be executed only on an instance of SQL Server that is hosting a secondary replica that has not yet been joined to the availability group.

Parameters
-InputObject <Server>

  • This value is required
  • Accepts pipeline input ByValue

The Server object of the instance of SQL Server that hosts the secondary replica.

-Name <string>

  • This value is required

The name of the availability group.

-Path <string>

The path to the instance of SQL Server that hosts the secondary replica to be joined to the availability group. This is an optional parameter. If not specified, the value of this parameter defaults to the current working location.

-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.Server

The availability replica to be joined to the availability group.

Examples
  1. This command joins a secondary replica hosted by the server instance located at the specified path to the availability group named ‘MyAg’:
    C:PS> Join-SqlAvailabilityGroup -Path SQLSERVER:SQLSecondaryServerInstanceName -Name 'MyAg'
    

    This server instance must host a secondary replica in this availability group.

  2. This command outputs the Transact-SQL script that joins a secondary replica hosted by the server instance located at the specified path to the availability group named ‘MyAg’:
    C:PS> Join-SqlAvailabilityGroup -Path SQLSERVER:SQLSecondaryServerInstanceName -Name 'MyAg' -Script
    

    This server instance must host a secondary replica in this availability group.

Additional Notes
 The high availability data recovery service must be enabled on the server instance, the availability replica 
 specified by Path must exist.