Execution Flow
Each database produces two result entries: one for removal from the AG (primary), and one per secondary replica where the database is dropped. Status codes:
RemovedFromAG, DroppedOnSecondary, NotInAG, RemoveFromAGFailed, DropOnSecondaryFailed, RemoveSkipped (WhatIf), DropSkipped (WhatIf).Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| -SqlInstance | String | Optional | Primary replica SQL instance. Default: $env:COMPUTERNAME. |
| -SqlCredential | PSCredential | Optional | SQL authentication credential. |
| -Database | String[] | Optional* | One or more database names to remove. Ignored when -All is set. |
| -All | Switch | Optional* | Removes all user databases that are currently members of any AG. |
| -EnableException | Switch | Optional | Throws terminating errors instead of returning an error status object. |
| -WhatIf / -Confirm | Switch | Optional | Standard ShouldProcess support. |
* Either -Database or -All must be provided.
Return Value
Returns an array of PSCustomObject, one per action, each with: SqlInstance, DatabaseName, Status, Message.
Examples
Example 1 — Remove a single database from its AG
Remove-sqmDatabaseFromAG -SqlInstance "SQL01" -Database "SalesDB"
Example 2 — Preview removal of all AG databases
Remove-sqmDatabaseFromAG -SqlInstance "SQL01" -All -WhatIf