Author | Stephen Bennett, sqlnotesfromtheunderground.wordpress.com |
Availability | Windows, Linux, macOS |
Want to see the source code for this command? Check out Find-DbaAgentJob on GitHub.
Want to see the Bill Of Health for this command? Check out Find-DbaAgentJob.
Find-DbaAgentJob finds agent jobs that fit certain search filters.
This command filters SQL Agent jobs giving the DBA a list of jobs that may need attention or could possibly be options for removal.
Find-DbaAgentJob
[-SqlInstance] <DbaInstanceParameter[]>
[[-SqlCredential] <PSCredential>]
[[-JobName] <String[]>]
[[-ExcludeJobName] <String[]>]
[[-StepName] <String[]>]
[[-LastUsed] <Int32>]
[-IsDisabled]
[-IsFailed]
[-IsNotScheduled]
[-IsNoEmailNotification]
[[-Category] <String[]>]
[[-Owner] <String>]
[[-Since] <DateTime>]
[-EnableException]
[<CommonParameters>]
PS C:\> Find-DbaAgentJob -SqlInstance Dev01 -JobName *backup*
Returns all agent job(s) that have backup in the name
PS C:\> Find-DbaAgentJob -SqlInstance Dev01, Dev02 -JobName Mybackup
Returns all agent job(s) that are named exactly Mybackup
PS C:\> Find-DbaAgentJob -SqlInstance Dev01 -LastUsed 10
Returns all agent job(s) that have not ran in 10 days
PS C:\> Find-DbaAgentJob -SqlInstance Dev01 -IsDisabled -IsNoEmailNotification -IsNotScheduled
Returns all agent job(s) that are either disabled, have no email notification or don't have a schedule. returned with detail
PS C:\> $servers | Find-DbaAgentJob -IsFailed | Start-DbaAgentJob
Finds all failed job then starts them. Consider using a -WhatIf at the end of Start-DbaAgentJob to see what it'll do first
PS C:\> Find-DbaAgentJob -SqlInstance Dev01 -LastUsed 10 -Exclude "Yearly - RollUp Workload", "SMS - Notification"
Returns all agent jobs that have not ran in the last 10 days ignoring jobs "Yearly - RollUp Workload" and "SMS - Notification"
PS C:\> Find-DbaAgentJob -SqlInstance Dev01 -Category "REPL-Distribution", "REPL-Snapshot" | Format-Table -AutoSize -Wrap
Returns all job/s on Dev01 that are in either category "REPL-Distribution" or "REPL-Snapshot"
PS C:\> Find-DbaAgentJob -SqlInstance Dev01, Dev02 -IsFailed -Since '2016-07-01 10:47:00'
Returns all agent job(s) on Dev01 and Dev02 that have failed since July of 2016 (and still have history in msdb)
PS C:\> Get-DbaRegServer -SqlInstance CMSServer -Group Production | Find-DbaAgentJob -Disabled -IsNotScheduled | Format-Table -AutoSize -Wrap
Queries CMS server to return all SQL instances in the Production folder and then list out all agent jobs that have either been disabled or have no schedule.
PS C:\> $Instances = 'SQL2017N5','SQL2019N5','SQL2019N20','SQL2019N21','SQL2019N22'
Find-DbaAgentJob -SqlInstance $Instances -JobName backup -IsNotScheduled
Returns all agent job(s) wiht backup in the name, that don't have a schedule on 'SQL2017N5','SQL2019N5','SQL2019N20','SQL2019N21','SQL2019N22'
The target SQL Server instance or instances. You must have sysadmin access and server version must be SQL Server version 2000 or higher.
Alias | |
Required | True |
Pipeline | true (ByValue) |
Default Value |
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.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Filter agent jobs to only the name(s) you list.
Supports regular expression (e.g. MyJob*) being passed in.
Alias | Name |
Required | False |
Pipeline | false |
Default Value |
Allows you to enter an array of agent job names to ignore
Alias | |
Required | False |
Pipeline | false |
Default Value |
Filter based on StepName.
Supports regular expression (e.g. MyJob*) being passed in.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Find all jobs that haven't ran in the INT number of previous day(s)
Alias | |
Required | False |
Pipeline | false |
Default Value | 0 |
Find all jobs that are disabled
Alias | Disabled |
Required | False |
Pipeline | false |
Default Value | False |
Find all jobs that have failed
Alias | Failed |
Required | False |
Pipeline | false |
Default Value | False |
Find all jobs with no schedule assigned
Alias | NoSchedule |
Required | False |
Pipeline | false |
Default Value | False |
Find all jobs without email notification configured
Alias | NoEmailNotification |
Required | False |
Pipeline | false |
Default Value | False |
Filter based on agent job categories
Alias | |
Required | False |
Pipeline | false |
Default Value |
Filter based on owner of the job/s
Alias | |
Required | False |
Pipeline | false |
Default Value |
Datetime object used to narrow the results to a date
Alias | |
Required | False |
Pipeline | false |
Default Value |
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.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |