< Back
Find-DbaAgentJob
Post
NAME Find-DbaAgentJob
SYNOPSIS
Find-DbaAgentJob finds agent jobs that fit certain search filters.
SYNTAX
Find-DbaAgentJob [-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]> [[-SqlCredential]
<Pscredential>] [[-JobName] <System.String[]>] [[-ExcludeJobName] <System.String[]>] [[-StepName]
<System.String[]>] [[-LastUsed] <Int>] [-IsDisabled <Switch>] [-IsFailed <Switch>] [-IsNotScheduled <Switch>]
[-IsNoEmailNotification <Switch>] [[-Category] <System.String[]>] [[-Owner] <String>] [[-Since] <Datetime>]
[-EnableException <Switch>] [<CommonParameters>]
DESCRIPTION
This command filters SQL Agent jobs giving the DBA a list of jobs that may need attention or could possibly be
options for removal.
PARAMETERS
-Category [<System.String[]>]
Filter based on agent job categories
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-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
-ExcludeJobName [<System.String[]>]
Allows you to enter an array of agent job names to ignore
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-IsDisabled [<Switch>]
Find all jobs that are disabled
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-IsFailed [<Switch>]
Find all jobs that have failed
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-IsNoEmailNotification [<Switch>]
Find all jobs without email notification configured
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-IsNotScheduled [<Switch>]
Find all jobs with no schedule assigned
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-JobName [<System.String[]>]
Filter agent jobs to only the name(s) you list.
Supports regular expression (e.g. MyJob*) being passed in.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-LastUsed [<Int>]
Find all jobs that haven't ran in the INT number of previous day(s)
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Owner [<String>]
Filter based on owner of the job/s
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Since [<Datetime>]
Datetime object used to narrow the results to a date
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. You must have sysadmin access and server version must be SQL
Server version 2000 or higher.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-StepName [<System.String[]>]
Filter based on StepName.
Supports regular expression (e.g. MyJob*) being passed in.
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: Agent, Job
Author: Stephen Bennett (https://sqlnotesfromtheunderground.wordpress.com/)
Website: https://dbatools.io
Copyright: (c) 2018 by dbatools, licensed under MIT
License: MIT https://opensource.org/licenses/MIT
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>Find-DbaAgentJob -SqlInstance Dev01 -JobName *backup*
Returns all agent job(s) that have backup in the name
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Find-DbaAgentJob -SqlInstance Dev01, Dev02 -JobName Mybackup
Returns all agent job(s) that are named exactly Mybackup
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>Find-DbaAgentJob -SqlInstance Dev01 -LastUsed 10
Returns all agent job(s) that have not ran in 10 days
-------------------------- EXAMPLE 4 --------------------------
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
-------------------------- EXAMPLE 5 --------------------------
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
-------------------------- EXAMPLE 6 --------------------------
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"
-------------------------- EXAMPLE 7 --------------------------
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"
-------------------------- EXAMPLE 8 --------------------------
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)
-------------------------- EXAMPLE 9 --------------------------
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.
RELATED LINKS
https://dbatools.io/Find-DbaAgentJob
SYNOPSIS
Find-DbaAgentJob finds agent jobs that fit certain search filters.
SYNTAX
Find-DbaAgentJob [-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]> [[-SqlCredential]
<Pscredential>] [[-JobName] <System.String[]>] [[-ExcludeJobName] <System.String[]>] [[-StepName]
<System.String[]>] [[-LastUsed] <Int>] [-IsDisabled <Switch>] [-IsFailed <Switch>] [-IsNotScheduled <Switch>]
[-IsNoEmailNotification <Switch>] [[-Category] <System.String[]>] [[-Owner] <String>] [[-Since] <Datetime>]
[-EnableException <Switch>] [<CommonParameters>]
DESCRIPTION
This command filters SQL Agent jobs giving the DBA a list of jobs that may need attention or could possibly be
options for removal.
PARAMETERS
-Category [<System.String[]>]
Filter based on agent job categories
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-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
-ExcludeJobName [<System.String[]>]
Allows you to enter an array of agent job names to ignore
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-IsDisabled [<Switch>]
Find all jobs that are disabled
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-IsFailed [<Switch>]
Find all jobs that have failed
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-IsNoEmailNotification [<Switch>]
Find all jobs without email notification configured
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-IsNotScheduled [<Switch>]
Find all jobs with no schedule assigned
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-JobName [<System.String[]>]
Filter agent jobs to only the name(s) you list.
Supports regular expression (e.g. MyJob*) being passed in.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-LastUsed [<Int>]
Find all jobs that haven't ran in the INT number of previous day(s)
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Owner [<String>]
Filter based on owner of the job/s
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Since [<Datetime>]
Datetime object used to narrow the results to a date
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. You must have sysadmin access and server version must be SQL
Server version 2000 or higher.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-StepName [<System.String[]>]
Filter based on StepName.
Supports regular expression (e.g. MyJob*) being passed in.
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: Agent, Job
Author: Stephen Bennett (https://sqlnotesfromtheunderground.wordpress.com/)
Website: https://dbatools.io
Copyright: (c) 2018 by dbatools, licensed under MIT
License: MIT https://opensource.org/licenses/MIT
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>Find-DbaAgentJob -SqlInstance Dev01 -JobName *backup*
Returns all agent job(s) that have backup in the name
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Find-DbaAgentJob -SqlInstance Dev01, Dev02 -JobName Mybackup
Returns all agent job(s) that are named exactly Mybackup
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>Find-DbaAgentJob -SqlInstance Dev01 -LastUsed 10
Returns all agent job(s) that have not ran in 10 days
-------------------------- EXAMPLE 4 --------------------------
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
-------------------------- EXAMPLE 5 --------------------------
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
-------------------------- EXAMPLE 6 --------------------------
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"
-------------------------- EXAMPLE 7 --------------------------
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"
-------------------------- EXAMPLE 8 --------------------------
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)
-------------------------- EXAMPLE 9 --------------------------
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.
RELATED LINKS
https://dbatools.io/Find-DbaAgentJob