commands

^

Set-DbaAgentJob

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.

Synopsis

Set-DbaAgentJob updates a job.

Description

Set-DbaAgentJob updates a job in the SQL Server Agent with parameters supplied.

Syntax

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>]

 

Examples

 

Example: 1
PS C:\> Set-DbaAgentJob sql1 -Job Job1 -Disabled

Changes the job to disabled

Example: 2
PS C:\> Set-DbaAgentJob sql1 -Job Job1 -OwnerLogin user1

Changes the owner of the job

Example: 3
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

Example: 4
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

Example: 5
PS C:\> Set-DbaAgentJob -SqlInstance sql1 -Job Job1, Job2, Job3 -Enabled

Changes multiple jobs to enabled

Example: 6
PS C:\> Set-DbaAgentJob -SqlInstance sql1, sql2, sql3 -Job Job1, Job2, Job3 -Enabled

Changes multiple jobs to enabled on multiple servers

Example: 7
PS C:\> Set-DbaAgentJob -SqlInstance sql1 -Job Job1 -Description 'Just another job' -Whatif

Doesn't Change the job but shows what would happen.

Example: 8
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

Example: 9
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

Optional Parameters

-SqlInstance

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
-SqlCredential

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
-Job

The name of the job.

Alias
Required False
Pipeline false
Default Value
-Schedule

Schedule to attach to job. This can be more than one schedule.

Alias
Required False
Pipeline false
Default Value
-ScheduleId

Schedule ID to attach to job. This can be more than one schedule ID.

Alias
Required False
Pipeline false
Default Value
-NewName

The new name for the job.

Alias
Required False
Pipeline false
Default Value
-Enabled

Enabled the job.

Alias
Required False
Pipeline false
Default Value False
-Disabled

Disabled the job

Alias
Required False
Pipeline false
Default Value False
-Description

The description of the job.

Alias
Required False
Pipeline false
Default Value
-StartStepId

The identification number of the first step to execute for the job.

Alias
Required False
Pipeline false
Default Value 0
-Category

The category of the job.

Alias
Required False
Pipeline false
Default Value
-OwnerLogin

The name of the login that owns the job.

Alias
Required False
Pipeline false
Default Value
-EventLogLevel

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
-EmailLevel

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
-NetsendLevel

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
-PageLevel

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
-EmailOperator

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
-NetsendOperator

The name of the operator to whom the network message is sent.

Alias
Required False
Pipeline false
Default Value
-PageOperator

The name of the operator to whom a page is sent.

Alias
Required False
Pipeline false
Default Value
-DeleteLevel

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
-Force

The force parameter will ignore some errors in the parameters and assume defaults.

Alias
Required False
Pipeline false
Default Value False
-InputObject

Enables piping job objects

Alias
Required False
Pipeline true (ByValue)
Default Value
-EnableException

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
-WhatIf

Shows what would happen if the command were to run. No actions are actually performed.

Alias wi
Required False
Pipeline false
Default Value
-Confirm

Prompts you for confirmation before executing any changing operations within the command.

Alias cf
Required False
Pipeline false
Default Value