Execution Flow
Calls
Invoke-sqmSqlAlwaysOnAutoseeding first to ensure AutoSeed is enabled before any repair. Each repair action (remove, drop, add) is written to the Windows Event Log source sqmAlwaysOn (created automatically). Use -NoReport to suppress event-log output in scheduled-job contexts.Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| -SqlInstance | String | Optional | Primary SQL instance. Default: $env:COMPUTERNAME. |
| -SqlCredential | PSCredential | Optional | SQL authentication credential. |
| -Force | Switch | Optional | Also repair databases that are already considered healthy (force refresh). |
| -NoReport | Switch | Optional | Suppress Windows Event Log writes (intended for scheduled-job execution). |
| -EnableException | Switch | Optional | Throw terminating errors instead of logging warnings. |
| -WhatIf / -Confirm | Switch | Optional | Standard ShouldProcess support. |
Return Value
Returns a PSCustomObject[] — one entry per repaired (or skipped) database — with: SqlInstance, AgName, DatabaseName, Action, Status, Message.
Examples
Example 1 — Repair all unhealthy AG databases on local instance
Repair-sqmAlwaysOnDatabases
Example 2 — Force repair of all databases including healthy ones
Repair-sqmAlwaysOnDatabases -SqlInstance "SQL01" -Force
Example 3 — Preview without changes
Repair-sqmAlwaysOnDatabases -SqlInstance "SQL01" -WhatIf