Remove-​Sql​Availability​Group

Removes an availability group.

Syntax

Remove-SqlAvailabilityGroup
      [-InputObject] <AvailabilityGroup[]>
      [-Script]
      [-Confirm]
      [-WhatIf]
      [<CommonParameters>]
Remove-SqlAvailabilityGroup
      [-Path] <String[]>
      [-Script]
      [-Confirm]
      [-WhatIf]
      [<CommonParameters>]

Description

The Remove-SqlAvailabilityGroup cmdlet removes an availability group in AlwaysOn Availability Groups. You can run this cmdlet on any instance of SQL Server that has AlwaysOn Availability Groups enabled on a Windows Server Failover Clustering (WSFC) node that has security credentials for the availability group.

Examples

Example 1: Remove an availabity group

PS C:\> Remove-SqlAvailabilityGroup -Path "SQLSERVER:\Sql\Server\InstanceName\AvailabilityGroups\MainAG"

This command removes the availability group named MainAG. You can run this command on any server instance that hosts an availability replica for the availability group.

Example 2: Remove all availability groups

PS C:\> Get-ChildItem "SQLSERVER:\Sql\Server\InstanceName\AvailabilityGroups" | Remove-SqlAvailabilityGroup

This command gets all availability groups that have availability replicas in the specified location in the SQLSERVER: provider. The command passes them to the current cmdlet by using the pipeline operator. That cmdlet deletes each availability group.

Example 3: Create a script to remove an availability group

PS C:\> Remove-SqlAvailabilityGroup -Path "SQLSERVER:\Sql\Server\InstanceName\AvailabilityGroups\MainAG" -Script

This command creates a Transact-SQL script that removes the availability group named MainAG. The command does not perform this action.

Required Parameters

-InputObject

Specifies availability group that this cmdlet removes.

Type:AvailabilityGroup[]
Position:2
Default value:None
Accept pipeline input:True (ByValue)
Accept wildcard characters:False
-Path

Specifies the path of the availability group that this cmdlet removes.

Type:String[]
Position:2
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

Optional Parameters

-Confirm

Prompts you for confirmation before running the cmdlet.

Type:SwitchParameter
Aliases:cf
Position:Named
Default value:False
Accept pipeline input:False
Accept wildcard characters:False
-Script

Indicates that this cmdlet returns a Transact-SQL script that performs the task that this cmdlet performs.

Type:SwitchParameter
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Type:SwitchParameter
Aliases:wi
Position:Named
Default value:False
Accept pipeline input:False
Accept wildcard characters:False

Inputs

Microsoft.SqlServer.Management.Smo.AvailabilityGroup