Execution Flow
Synopsis
Two separate DMV queries collect active long-operations: dm_exec_requests for Backup/Restore (filtered by percent_complete > 0) and dm_hadr_physical_seeding_stats for AutoSeed (SQL 2016+; gracefully skipped on older versions). Output is formatted for the console using Format-sqmTimeSpan and Format-sqmFileSize. There is no file export — results are returned via the pipeline.
Requires dbatools. AutoSeed monitoring requires SQL Server 2016+. With
-Continuous, the function loops until interrupted (Ctrl+C), clearing the console on each refresh. No -OutputPath parameter; this function is console-only.Syntax
Get-sqmOperationStatus [-SqlInstance <String>] [-SqlCredential <PSCredential>] [-OperationType <String>] # Backup | Restore | AutoSeed | All (default: All) [-Continuous] [-RefreshSeconds <Int>] # default 10 [-EnableException]
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| -SqlInstance | String | $env:COMPUTERNAME | SQL Server instance to monitor. |
| -SqlCredential | PSCredential | — | SQL connection credential. |
| -OperationType | String | All | Filter to Backup, Restore, AutoSeed, or All. |
| -Continuous | Switch | false | Loop with Clear-Host; press Ctrl+C to stop. |
| -RefreshSeconds | Int | 10 | Seconds between refreshes in Continuous mode. |
| -EnableException | Switch | false | Throw terminating exceptions. |
Return Value
| Property | Description |
|---|---|
| OperationType | Backup, Restore, or AutoSeed. |
| DatabaseName | Target database name. |
| PercentComplete | Progress percentage (Backup/Restore). AutoSeed uses TransferRate instead. |
| ElapsedTime | Formatted elapsed time (Format-sqmTimeSpan). |
| EstimatedTimeRemaining | Formatted estimated time remaining. |
| TransferRate | AutoSeed: transfer_rate_bytes_per_second (formatted). |
| TransferredSize | AutoSeed: transferred_size_bytes (formatted). |
| Role | AutoSeed: role_desc (PRIMARY / SECONDARY). |
Examples
# One-shot: show all active operations Get-sqmOperationStatus -SqlInstance "SQL01" # Watch backup progress, refresh every 5 seconds Get-sqmOperationStatus -SqlInstance "SQL01" -OperationType "Backup" -Continuous -RefreshSeconds 5 # AutoSeed only (Always On Seeding) Get-sqmOperationStatus -OperationType "AutoSeed" -Continuous