Invoke-sqmFailover
Always OnsqmSQLTool v1.8.2+ · Operations⚠ High Impact ✓ Pre/Post Checks
Pre-checks: Synchronization status, redo queue size (
-MaxRedoQueueMB, default 50 MB).Failover: Executes
ALTER AVAILABILITY GROUP ... FAILOVER on the target secondary replica (automatically selects the first SYNCHRONIZED secondary if not specified).Post-checks: New primary reachability, all databases reach SYNCHRONIZED state.
Parameters
| Parameter | Type | Required | Default | Notes |
|---|---|---|---|---|
| -SqlInstance | string | Required | — | Current PRIMARY instance. |
| -SqlCredential | PSCredential | Optional | — | Credentials for the connection. |
| -AvailabilityGroup | string | Required | — | Name of the availability group. |
| -TargetReplica | string | Optional | Auto-select first SYNCHRONIZED | Instance name of the target secondary. If not specified, the first SYNCHRONIZED secondary is chosen automatically. |
| -MaxRedoQueueMB | int | Optional | 50 | Maximum redo queue size in MB. Failover is aborted if exceeded. |
| -WaitAfterFailoverSeconds | int | Optional | 30 | Wait time (5-300 seconds) after failover before post-checks run. |
| -ContinueOnError | switch | Switch | $false | Return result object instead of throwing errors. |
| -EnableException | switch | Switch | $false | Throw exceptions immediately. |
| -WhatIf / -Confirm | switch | Optional | — | ShouldProcess (ConfirmImpact: High) guards failover execution. |
Execution Flow
Examples
Test failover with -WhatIf
Invoke-sqmFailover -SqlInstance "SQL01" -AvailabilityGroup "AG_Prod" -WhatIf
Failover to specific replica with custom redo queue threshold
Invoke-sqmFailover -SqlInstance "SQL01" -AvailabilityGroup "AG_Prod" -TargetReplica "SQL02" -MaxRedoQueueMB 10