We recommend using Visual Studio 2017

Job.EnumHistory Method (JobHistoryFilter)

Enumerates a list of execution history associated with the referenced job.

Namespace:  Microsoft.SqlServer.Management.Smo.Agent
Assembly:  Microsoft.SqlServer.Smo (in Microsoft.SqlServer.Smo.dll)

public DataTable EnumHistory(
	JobHistoryFilter filter
)

Parameters

filter
Type: Microsoft.SqlServer.Management.Smo.Agent.JobHistoryFilter
A JobHistoryFilter object value that specifies constraints on the data returned.

Return Value

Type: System.Data.DataTable
A DataTable object value that contains execution history data for the referenced job.

The following code example creates a job then displays its filtered execution history.

C#

Server srv = new Server("(local)");
Job jb = srv.JobServer.Jobs["Test Job"];
JobHistoryFilter jhf = new JobHistoryFilter();
jhf.JobID = jb.JobID
DataTable jobHistory = jb.EnumHistory(jhf);

PowerShell

$srv = new-object Microsoft.SqlServer.Management.Smo.Server("(local)")
$jb = $srv.JobServer.Jobs["Test Job"]
$jhf = new-object Microsoft.SqlServer.Management.Smo.Agent.JobHistoryFilter
$jhf.JobID = $jb.JobID
$jobHistory = $jb.EnumHistory($jhf)

Community Additions

ADD
Show: