Commands / Test-sqmDistributedAgReadiness
Distributed AG

Test-sqmDistributedAgReadiness

Runs a battery of readiness checks against a Distributed Availability Group before a planned failover: replica synchronization health, DAG-level sync, listener status, and optional network reachability to the secondary cluster. Produces a 0–100 readiness score.

Module: sqmSQLTool
Requires: dbatools
ShouldProcess: No
Output: PSCustomObject

Execution Flow

START Check 1: COUNT(*) sys.availability_groups WHERE is_distributed=1 DAG exists? Score = 0, stop 4 checks, each contributes 1 unit to the readiness score Check 2: Replica Synchronization — Healthy / Total Check 3: DAG Synchronization — LSN hardened == sent, per replica Check 4: AG Listener Status — Online / Total configured -TargetInstance given? Check 5: Test-NetConnection ReadinessScore = round(PASS count × 100 / total checks) Score buckets 100 / ≥75 / <75 100 → READY ≥75 → MOSTLY_READY <75 → NOT_READY Return PSCustomObject (ReadinessScore, Status, CheckResults[]) DONE
The network check (Check 5) is optional and only runs when -TargetInstance is supplied — with it present, a failed network test still only costs one check out of five toward the score, so a firewall-blocked secondary doesn't automatically read as NOT_READY unless the DB-level checks are also unhealthy. This is a pre-flight readiness assessment, not a failover trigger — pair it with Invoke-sqmDistributedFailover.

Parameters

ParameterTypeRequiredDescription
-SqlInstanceStringOptionalPrimary SQL Server instance. Default: local computer name. Pipeline-capable.
-SqlCredentialPSCredentialOptionalSQL authentication credential for the connection.
-TargetInstanceStringOptionalSecondary SQL Server instance for the optional network reachability test.
-OutputPathStringOptionalOutput directory for report files. Default: C:\System\WinSrvLog\MSSQL.
-EnableExceptionSwitchOptionalThrow exceptions immediately instead of returning a Score of 0.

Return Value

Returns a single PSCustomObject with: SqlInstance, Timestamp, ReadinessScore (0–100), Status (READY, MOSTLY_READY, or NOT_READY), CheckResults (array of per-check Check/Result/Details objects).

Examples

Example 1 — Check readiness including network test to the DR side

Test-sqmDistributedAgReadiness -SqlInstance "SQL01" -TargetInstance "DR-SQL01"

Example 2 — Database-level checks only, no network test

Test-sqmDistributedAgReadiness -SqlInstance "SQL01"

Example 3 — Gate a failover script on full readiness

$r = Test-sqmDistributedAgReadiness -SqlInstance "SQL01" -TargetInstance "DR-SQL01"
if ($r.Status -eq 'READY') { Invoke-sqmDistributedFailover -SqlInstance "SQL01" }