Performs a controlled failover of a Distributed Availability Group. Validates readiness (score ≥ 75/100 via Test-sqmDistributedAgReadiness), discovers the secondary AG from sys.availability_replicas, issues ALTER AVAILABILITY GROUP … FAILOVER, verifies the new primary role, and exports a detailed TXT report. Use -Rollback to fail back after a failed migration without the readiness check.
Execution Flow
Synopsis
For a normal failover, Test-sqmDistributedAgReadiness is called first; a ReadinessScore below 75 aborts the operation. The secondary AG and its server are discovered via a T-SQL query against sys.availability_groups (SQL 2016 compatible — no dm_hadr_distributed_ag_replica_member_status). Without -Force, a ShouldProcess prompt is shown. The failover uses ALTER AVAILABILITY GROUP … FAILOVER (no FORCE_FAILOVER_ALLOW_DATA_LOSS). After a 3-second pause, replica roles are verified and a TXT report is written to -OutputPath.
-Rollback skips the readiness check and is intended for fail-back after a failed migration. Use with caution — it performs the same FAILOVER SQL statement.
Critical operation. Always test in a DR environment first. The readiness check only validates synchronization health — it does not guarantee zero data loss. Always verify the report after the operation.