Skip to content

Remove-DbaAgDatabase - Honor the AvailabilityGroup filter - #10608

Open
andreasjordan wants to merge 2 commits into
developmentfrom
fix-removedbaagdatabase-availabilitygroup
Open

Remove-DbaAgDatabase - Honor the AvailabilityGroup filter#10608
andreasjordan wants to merge 2 commits into
developmentfrom
fix-removedbaagdatabase-availabilitygroup

Conversation

@andreasjordan

@andreasjordan andreasjordan commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

Problem

Remove-DbaAgDatabase declares and documents -AvailabilityGroup ("Limits the operation to databases within specific availability groups") but never uses it. The internal Get-DbaAgDatabase call only received -Database, so a removal scoped to one availability group removed the database from whatever availability group actually contained it.

What changed

The -AvailabilityGroup parameter is now passed through to Get-DbaAgDatabase, which already supported it. The call was converted to a splat per the style guide.

What deliberately did not change

  • The pipeline path (-InputObject) is untouched: piped objects are already the caller's explicit selection.
  • The error text for the -SqlInstance path used to demand "one or more Availability Groups" although the check only requires -Database; a follow-up commit on this branch corrects the wording to match what is actually required.

Tests

Added a regression test that creates a second availability group, scopes a removal to it, and asserts the database in the first availability group survives and nothing is returned. Verified against the lab HADR instance (SQL Server 2025): the new test fails on the old code with exactly the reported behavior (Status=Removed for the out-of-scope database) and the full file passes with the fix (4/4).

Found by @greenmtnsun via static analysis, reported in #10607.

🤖 Generated with Claude Code

…Database

The parameter was declared and documented but never used, so a removal
scoped to one availability group removed the database from whatever
availability group it was in. The regression test scopes a removal to a
second availability group and asserts the database survives.

Found via static analysis by @greenmtnsun in #10607.

(do Remove-DbaAgDatabase)
…oes not require

The error text told the user to specify one or more availability
groups, but the condition only ever required -Database. The
AvailabilityGroup parameter is an optional filter.

(do Remove-DbaAgDatabase)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant