Get-DbaAgentJobHistory

Gets execution history of SQL Agent Job on an instance(s) of SQL Server.

Get-DbaAgentJobHistory returns all information on the executions still available on each instance(s) of SQL Server submitted.
The cleanup of SQL Agent history determines how many records are kept.
https://msdn.microsoft.com/en-us/library/ms201680.aspx
https://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.agent.jobhistoryfilter(v=sql.120).aspx

Screenshots

dbatools - Get-DbaAgentJobHistory

Examples

Returns all SQL Agent Job execution results on the local default SQL Server instance.

Get-DbaAgentJobHistory -SqlInstance localhost

Returns all SQL Agent Job execution results for the local and sql2016 SQL Server instances.

Get-DbaAgentJobHistory -SqlInstance localhost, sql2016

Returns all SQL Agent Job execution results for sql1 and sql2\Inst2K17.

‘sql1′,’sql2\Inst2K17’ | Get-DbaAgentJobHistory

Returns all properties for all SQL Agent Job execution results on sql2\Inst2K17.

Get-DbaAgentJobHistory -SqlInstance sql2\Inst2K17 | select *

Returns all properties for all SQL Agent Job execution results of the ‘Output File Cleanup’ job on sql2\Inst2K17.

Get-DbaAgentJobHistory -SqlInstance sql2\Inst2K17 -Job ‘Output File Cleanup’

Returns all properties for all SQL Agent Job execution results of the ‘Output File Cleanup’ job on sql2\Inst2K17, with additional properties that show the output filename path

Get-DbaAgentJobHistory -SqlInstance sql2\Inst2K17 -Job ‘Output File Cleanup’ -WithOutputFile

Returns the SQL Agent Job execution results for the whole jobs on sql2\Inst2K17, leaving out job step execution results.

Get-DbaAgentJobHistory -SqlInstance sql2\Inst2K17 -NoJobSteps

Returns the SQL Agent Job execution results between 2017/05/22 00:00:00 and 2017/05/23 12:30:00 on sql2\Inst2K17.

Get-DbaAgentJobHistory -SqlInstance sql2\Inst2K17 -StartDate ‘2017-05-22’ -EndDate ‘2017-05-23 12:30:00’

Gets all jobs with the name that matches the regex pattern “backup” and then gets the job history from those. You can also use -Like backup in this example.

Get-DbaAgentJob -SqlInstance sql2016 | Where Name -match backup | Get-DbaAgentJobHistory

Author

This command was created by Klaas Vandenberghe. You can find Klaas on Twitter and his blog.