Skip to content

Commit bbc9d63

Browse files
Remove-DbaAvailabilityGroup - remove checks
No idea how this got in when it broke all the tests
1 parent 9cf09cf commit bbc9d63

File tree

1 file changed

+3
-32
lines changed

1 file changed

+3
-32
lines changed

public/Remove-DbaAvailabilityGroup.ps1

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -98,40 +98,11 @@ function Remove-DbaAvailabilityGroup {
9898
if ($SqlInstance) {
9999
$InputObject += Get-DbaAvailabilityGroup -SqlInstance $SqlInstance -SqlCredential $SqlCredential -AvailabilityGroup $AvailabilityGroup
100100
}
101-
102101
foreach ($ag in $InputObject) {
103-
$clusterType = 'WSFC'
104-
try {
105-
$result = $ag.Parent.Query("SELECT cluster_type_desc FROM sys.availability_groups WHERE name = N'$($ag.Name)'")
106-
if ($result -and $result.cluster_type_desc) { $clusterType = $result.cluster_type_desc }
107-
} catch { $clusterType = 'WSFC' }
108-
109-
$majorVersion = [int]($ag.Parent.Query("SELECT CAST(SERVERPROPERTY('ProductMajorVersion') AS int) AS v").v)
110-
111-
if ($clusterType -eq 'WSFC') {
112-
try {
113-
$isClustered = $ag.Parent.Query("SELECT CONVERT(bit, SERVERPROPERTY('IsClustered')) AS IsClustered").IsClustered
114-
if (-not $isClustered -and -not $Force) {
115-
Write-Warning "Skipping $($ag.Name): WSFC-type AG but instance not clustered. Use -Force to remove anyway."
116-
continue
117-
}
118-
} catch {
119-
if (-not $Force) {
120-
Write-Warning "Skipping $($ag.Name): unable to determine cluster state. Use -Force to ignore."
121-
continue
122-
}
123-
}
124-
}
125-
126-
if ($Pscmdlet.ShouldProcess($ag.Parent.Name, "Removing availability group $($ag.Name)")) {
102+
if ($Pscmdlet.ShouldProcess($ag.Parent.Name, "Removing availability group $ag")) {
103+
# avoid enumeration issues
127104
try {
128-
# For SQL 2017+ non-clustered AGs, append WITH (CLUSTER_TYPE = NONE)
129-
if ($majorVersion -ge 14 -and ($clusterType -eq 'NONE' -or -not $isClustered)) {
130-
$ag.Parent.Query("DROP AVAILABILITY GROUP [$($ag.Name)] WITH (CLUSTER_TYPE = NONE)")
131-
} else {
132-
$ag.Parent.Query("DROP AVAILABILITY GROUP [$($ag.Name)]")
133-
}
134-
105+
$null = $ag.Parent.Query("DROP AVAILABILITY GROUP $ag")
135106
[PSCustomObject]@{
136107
ComputerName = $ag.ComputerName
137108
InstanceName = $ag.InstanceName

0 commit comments

Comments
 (0)