< Back

Get-DbaAgentJobHistory

Mon Jan 13, 2020 10:17 am

NAME Get-DbaAgentJobHistory



SYNOPSIS

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





SYNTAX

Get-DbaAgentJobHistory [-SqlCredential <Pscredential>] [-Job <System.Object[]>] [-ExcludeJob <System.Object[]>]

[-StartDate <Datetime>] [-EndDate <Datetime>] [-ExcludeJobSteps <Switch>] [-WithOutputFile <Switch>]

[-EnableException <Switch>] [<CommonParameters>]



Get-DbaAgentJobHistory -SqlInstance <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]> [-SqlCredential

<Pscredential>] [-Job <System.Object[]>] [-ExcludeJob <System.Object[]>] [-StartDate <Datetime>] [-EndDate

<Datetime>] [-ExcludeJobSteps <Switch>] [-WithOutputFile <Switch>] [-EnableException <Switch>] [<CommonParameters>]



Get-DbaAgentJobHistory [-SqlCredential <Pscredential>] [-Job <System.Object[]>] [-ExcludeJob <System.Object[]>]

[-StartDate <Datetime>] [-EndDate <Datetime>] [-ExcludeJobSteps <Switch>] [-WithOutputFile <Switch>]

-JobCollection <Microsoft.SqlServer.Management.Smo.Agent.Job> [-EnableException <Switch>] [<CommonParameters>]





DESCRIPTION

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/librar ... .120).aspx





PARAMETERS

-EnableException [<Switch>]

By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.

This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables

advanced scripting.

Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own

try/catch.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-EndDate [<Datetime>]

The DateTime before which the history is wanted. If unspecified, all available records will be processed.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-ExcludeJob [<System.Object[]>]

The job(s) to exclude - this list is auto-populated from the server



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-ExcludeJobSteps [<Switch>]

Use this switch to discard all job steps, and return only the job totals



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Job [<System.Object[]>]

The name of the job from which the history is wanted. If unspecified, all jobs will be processed.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-JobCollection [<Microsoft.SqlServer.Management.Smo.Agent.Job>]

An array of SMO jobs



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SqlCredential [<Pscredential>]

Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).



Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory -

Integrated are all supported.



For MFA support, please use Connect-DbaInstance.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SqlInstance [<Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>]

The target SQL Server instance or instances. This can be a collection and receive pipeline input to allow the

function to be executed against multiple SQL Server instances.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-StartDate [<Datetime>]

The DateTime starting from which the history is wanted. If unspecified, all available records will be

processed.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-WithOutputFile [<Switch>]

Use this switch to retrieve the output file (only if you want step details). Bonus points, we handle the quirks

of SQL Agent tokens to the best of our knowledge

(https://technet.microsoft.com/it-it/lib ... .110).aspx)



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



NOTES





Tags: Job, Agent

Author: Klaas Vandenberghe (@PowerDbaKlaas) | Simone Bizzotto (@niphold)



Website: https://dbatools.io

Copyright: (c) 2018 by dbatools, licensed under MIT

License: MIT https://opensource.org/licenses/MIT



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>Get-DbaAgentJobHistory -SqlInstance localhost



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

-------------------------- EXAMPLE 2 --------------------------



PS C:\\>Get-DbaAgentJobHistory -SqlInstance localhost, sql2016



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

-------------------------- EXAMPLE 3 --------------------------



PS C:\\>'sql1','sql2\\Inst2K17' | Get-DbaAgentJobHistory



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

-------------------------- EXAMPLE 4 --------------------------



PS C:\\>Get-DbaAgentJobHistory -SqlInstance sql2\\Inst2K17 | Select-Object *



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

-------------------------- EXAMPLE 5 --------------------------



PS C:\\>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.

-------------------------- EXAMPLE 6 --------------------------



PS C:\\>Get-DbaAgentJobHistory -SqlInstance sql2\\Inst2K17 -Job 'Output File Cleanup' -WithOutputFile



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

-------------------------- EXAMPLE 7 --------------------------



PS C:\\>Get-DbaAgentJobHistory -SqlInstance sql2\\Inst2K17 -ExcludeJobSteps



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

results.

-------------------------- EXAMPLE 8 --------------------------



PS C:\\>Get-DbaAgentJobHistory -SqlInstance sql2\\Inst2K17 -StartDate '2017-05-22' -EndDate '2017-05-23 12:30:00'



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

-------------------------- EXAMPLE 9 --------------------------



PS C:\\>Get-DbaAgentJob -SqlInstance sql2016 | Where-Object Name -Match backup | Get-DbaAgentJobHistory



Gets all jobs with the name that match the regex pattern "backup" and then gets the job history from those. You

can also use -Like *backup* in this example.



RELATED LINKS

https://dbatools.io/Get-DbaAgentJobHistory