Remove-SqlAvailabilityGroup

Removes the availability group specified by the InputObject or Path parameter.
Remove-SqlAvailabilityGroup [-Path*] <string> [-Script] [-Confirm] [-WhatIf] [<CommonParameters>]
Remove-SqlAvailabilityGroup [-InputObject*] <AvailabilityGroup> [-Script] [-Confirm] [-WhatIf] [<CommonParameters>]

The Remove-SqlAvailabilityGroup cmdlet removes the availability group specified by the InputObject or Path parameter. This cmdlet can remove availability groups that have been partially created. The cmdlet can be executed on any instance of SQL Server that has been enabled for AlwaysOn Availability Groups on a WSFC node that possess the correct security credentials for the availability group. Errors are thrown if the instance on which this cmdlet is executed is not enabled for AlwaysOn Availability Groups or if the availability group specified by the Path parameter does not exist.

Parameters
-InputObject <AvailabilityGroup>

  • This value is required
  • Accepts pipeline input ByValue

The AvailabilityGroup object of the availability group to be removed.

-Path <string>

  • This value is required

The path to the availability group. 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.AvailabilityGroup

Examples
  1. This command removes the availability group named ‘MyAg’:
    C:PS> Remove-SqlAvailabilityGroup -Path SQLSERVER:SqlComputerInstanceAvailabilityGroupsMyAg
    

    This command can be executed on any server instance that hosts an availability replica for the availability group.

  2. This command removes all availability groups with availability replicas that are hosted by the server instance named ‘ComputerInstance’:
    C:PS> Get-ChildItem SQLSERVER:SqlComputerInstanceAvailabilityGroups | Remove-SqlAvailabilityGroup
    
  3. This command outputs the Transact-SQL script that removes the availability group named ‘MyAg’:
    C:PS> Remove-SqlAvailabilityGroup -Path SQLSERVER:SqlComputerInstanceAvailabilityGroupsMyAg -Script
    

    The availability group is not actually removed by this command.

Additional Notes