Execution Flow
Synopsis
Queries all AGs on the given SQL Server instance via dbatools and DMVs - the same query and threshold scoring as Get-sqmAlwaysOnHealthReport, factored into a shared private helper so the logic only exists once. For each AG, every replica/database row is evaluated: redo queue, send queue, synchronization state, connection state, and suspend status determine an OverallStatus (OK / Warning / Critical). Nothing is written to disk - rows are returned straight to the pipeline, one call per instance.
Why this exists alongside Get-sqmAlwaysOnHealthReport
Get-sqmAlwaysOnHealthReport writes a TXT, CSV, and interactive HTML report file to disk on every call - fine for an on-demand report, wrong for something invoked every few minutes by a central-poller (e.g. the SQLLiveDiagnose collector monitoring several instances). Get-sqmAlwaysOnQueueStatus is that same data with the file I/O removed: same parameters, same threshold logic, no -OutputPath/-OutputHtml, just the row objects.
Syntax
Get-sqmAlwaysOnQueueStatus [-SqlInstance <String[]>] # pipeline [-SqlCredential <PSCredential>] [-MaxRedoQueueMB <Int>] [-MaxSendQueueMB <Int>] [-EnableException]
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| -SqlInstance | String[] | $env:COMPUTERNAME | SQL Server instance(s) to query. Pipeline-capable. |
| -SqlCredential | PSCredential | — | Credential for the SQL connection. |
| -MaxRedoQueueMB | Int | 100 | Redo queue warning threshold in MB (secondary replicas). |
| -MaxSendQueueMB | Int | 50 | Send queue warning threshold in MB. |
| -EnableException | Switch | false | Throw terminating exceptions instead of Write-Error. |
OverallStatus Logic
| Status | Condition |
|---|---|
| Critical | DbSyncState not in (SYNCHRONIZED/SYNCHRONIZING) OR ConnectionState ≠ CONNECTED OR IsSuspended = true. |
| Warning | RedoQueueMB > MaxRedoQueueMB (secondary) OR SendQueueMB > MaxSendQueueMB. |
| OK | All checks passed. |
Examples
Example 1, Queue status for the local instance
Get-sqmAlwaysOnQueueStatusExample 2, Only rows that need attention
Get-sqmAlwaysOnQueueStatus -SqlInstance "SQL01" -MaxRedoQueueMB 200 | Where-Object OverallStatus -ne 'OK'Example 3, Poll several instances and push into a repository table
"SQL01","SQL02" | Get-sqmAlwaysOnQueueStatus | Write-DbaDbTableData -SqlInstance "Repo01" -Database "SQLLiveDiagnose" -Table "AlwaysOnQueueSnapshot"