Get-sqmAgentJobHistory
Performance
sqmSQLTool v1.8.2+ · Monitoring
Xh Ym Zs.
Can optionally export results to CSV for auditing or reporting.
Parameters
| Parameter | Type | Required | Default | Notes |
|---|---|---|---|---|
| -SqlInstance | string | Optional | $env:COMPUTERNAME | Target SQL Server instance. |
| -SqlCredential | PSCredential | Optional | — | Credentials for the connection. |
| -JobName | string | Optional | * = all jobs | Job name or wildcard pattern (e.g. *Backup*). |
| -Status | string | Optional | — | Filter by outcome: Success, Failure, Retry, Cancelled. Default: all statuses. |
| -Since | datetime | Optional | 7 days ago | Show history from this date onwards. |
| -LastX | int | Optional | — | Instead of a time range: return the last X executions per job. |
| -OutputPath | string | Optional | — | Optional CSV export path. |
| -EnableException | switch | Switch | $false | Re-throw exceptions instead of returning $null. |
Execution Flow
Examples
Get all job history from the last 7 days (default)
Get-sqmAgentJobHistory
Get failed backup job history from the last 24 hours
Get-sqmAgentJobHistory -JobName "*Backup*" -Status Failure -Since (Get-Date).AddDays(-1)
Get last 5 executions per job and export to CSV
Get-sqmAgentJobHistory -LastX 5 -OutputPath "D:\Reports\job-history.csv"