Author | Sander Stad (@sqlstad), sqlstad.nl |
Availability | Windows, Linux, macOS |
Want to see the source code for this command? Check out Set-DbaAgentJob on GitHub.
Want to see the Bill Of Health for this command? Check out Set-DbaAgentJob.
Set-DbaAgentJob updates a job.
Set-DbaAgentJob updates a job in the SQL Server Agent with parameters supplied.
Set-DbaAgentJob
[[-SqlInstance] <DbaInstanceParameter[]>]
[[-SqlCredential] <PSCredential>]
[[-Job] <Object[]>]
[[-Schedule] <Object[]>]
[[-ScheduleId] <Int32[]>]
[[-NewName] <String>]
[-Enabled]
[-Disabled]
[[-Description] <String>]
[[-StartStepId] <Int32>]
[[-Category] <String>]
[[-OwnerLogin] <String>]
[[-EventLogLevel] <Object>]
[[-EmailLevel] <Object>]
[[-NetsendLevel] <Object>]
[[-PageLevel] <Object>]
[[-EmailOperator] <String>]
[[-NetsendOperator] <String>]
[[-PageOperator] <String>]
[[-DeleteLevel] <Object>]
[-Force]
[[-InputObject] <Job[]>]
[-EnableException]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
PS C:\> Set-DbaAgentJob sql1 -Job Job1 -Disabled
Changes the job to disabled
PS C:\> Set-DbaAgentJob sql1 -Job Job1 -OwnerLogin user1
Changes the owner of the job
PS C:\> Set-DbaAgentJob -SqlInstance sql1 -Job Job1 -EventLogLevel OnSuccess
Changes the job and sets the notification to write to the Windows Application event log on success
PS C:\> Set-DbaAgentJob -SqlInstance sql1 -Job Job1 -EmailLevel OnFailure -EmailOperator dba
Changes the job and sets the notification to send an e-mail to the e-mail operator
PS C:\> Set-DbaAgentJob -SqlInstance sql1 -Job Job1, Job2, Job3 -Enabled
Changes multiple jobs to enabled
PS C:\> Set-DbaAgentJob -SqlInstance sql1, sql2, sql3 -Job Job1, Job2, Job3 -Enabled
Changes multiple jobs to enabled on multiple servers
PS C:\> Set-DbaAgentJob -SqlInstance sql1 -Job Job1 -Description 'Just another job' -Whatif
Doesn't Change the job but shows what would happen.
PS C:\> Set-DbaAgentJob -SqlInstance sql1, sql2, sql3 -Job 'Job One' -Description 'Job One'
Changes a job with the name "Job1" on multiple servers to have another description
PS C:\> sql1, sql2, sql3 | Set-DbaAgentJob -Job Job1 -Description 'Job One'
Changes a job with the name "Job1" on multiple servers to have another description using pipe line
The target SQL Server instance or instances. You must have sysadmin access and server version must be SQL Server version 2000 or greater.
Alias | |
Required | False |
Pipeline | false |
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 |
The name of the job.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Schedule to attach to job. This can be more than one schedule.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Schedule ID to attach to job. This can be more than one schedule ID.
Alias | |
Required | False |
Pipeline | false |
Default Value |
The new name for the job.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Enabled the job.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
Disabled the job
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
The description of the job.
Alias | |
Required | False |
Pipeline | false |
Default Value |
The identification number of the first step to execute for the job.
Alias | |
Required | False |
Pipeline | false |
Default Value | 0 |
The category of the job.
Alias | |
Required | False |
Pipeline | false |
Default Value |
The name of the login that owns the job.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Specifies when to place an entry in the Microsoft Windows application log for this job.
Allowed values 0, "Never", 1, "OnSuccess", 2, "OnFailure", 3, "Always"
The text value van either be lowercase, uppercase or something in between as long as the text is correct.
Alias | |
Required | False |
Pipeline | false |
Default Value | |
Accepted Values | 0,Never,1,OnSuccess,2,OnFailure,3,Always |
Specifies when to send an e-mail upon the completion of this job.
Allowed values 0, "Never", 1, "OnSuccess", 2, "OnFailure", 3, "Always"
The text value van either be lowercase, uppercase or something in between as long as the text is correct.
Alias | |
Required | False |
Pipeline | false |
Default Value | |
Accepted Values | 0,Never,1,OnSuccess,2,OnFailure,3,Always |
Specifies when to send a network message upon the completion of this job.
Allowed values 0, "Never", 1, "OnSuccess", 2, "OnFailure", 3, "Always"
The text value van either be lowercase, uppercase or something in between as long as the text is correct.
Alias | |
Required | False |
Pipeline | false |
Default Value | |
Accepted Values | 0,Never,1,OnSuccess,2,OnFailure,3,Always |
Specifies when to send a page upon the completion of this job.
Allowed values 0, "Never", 1, "OnSuccess", 2, "OnFailure", 3, "Always"
The text value van either be lowercase, uppercase or something in between as long as the text is correct.
Alias | |
Required | False |
Pipeline | false |
Default Value | |
Accepted Values | 0,Never,1,OnSuccess,2,OnFailure,3,Always |
The e-mail name of the operator to whom the e-mail is sent when EmailLevel is reached.
Alias | |
Required | False |
Pipeline | false |
Default Value |
The name of the operator to whom the network message is sent.
Alias | |
Required | False |
Pipeline | false |
Default Value |
The name of the operator to whom a page is sent.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Specifies when to delete the job.
Allowed values 0, "Never", 1, "OnSuccess", 2, "OnFailure", 3, "Always"
The text value van either be lowercase, uppercase or something in between as long as the text is correct.
Alias | |
Required | False |
Pipeline | false |
Default Value | |
Accepted Values | 0,Never,1,OnSuccess,2,OnFailure,3,Always |
The force parameter will ignore some errors in the parameters and assume defaults.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
Enables piping job objects
Alias | |
Required | False |
Pipeline | true (ByValue) |
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 |
Shows what would happen if the command were to run. No actions are actually performed.
Alias | wi |
Required | False |
Pipeline | false |
Default Value |
Prompts you for confirmation before executing any changing operations within the command.
Alias | cf |
Required | False |
Pipeline | false |
Default Value |