Execution Flow
Each repair step is written to the Windows Application event log (source
sqmAlwaysOn, EventId 1000=start / 1001=success / 1002=failure). The source is auto-created on first run. The function is called by the New-sqmAlwaysOnRepairJob hourly Agent job.Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| -SqlInstance | String | Optional | Primary replica SQL instance. Default: $env:COMPUTERNAME. |
| -SqlCredential | PSCredential | Optional | SQL authentication credential. |
| -Force | Switch | Optional | Repairs all AG databases, including those that are currently HEALTHY (forced refresh). |
| -NoReport | Switch | Optional | Skips report generation (intended for use in scheduled job context). |
| -EnableException | Switch | Optional | Throws terminating errors instead of returning an error status object. |
| -WhatIf | Switch | Optional | Shows what would be repaired without making changes. |
Return Value
Returns an array of PSCustomObject, one per repaired database, each with: SqlInstance, DatabaseName, AvailabilityGroup, Status (RepairSuccess / RepairFailed), Message.
Examples
Example 1 — Repair all unhealthy AG databases
Repair-sqmAlwaysOnDatabases -SqlInstance "SQL01"
Example 2 — Force repair all databases (including healthy)
Repair-sqmAlwaysOnDatabases -SqlInstance "SQL01" -Force