< Back

Set-DbaAgentJob

Mon Jan 13, 2020 5:25 pm

NAME Set-DbaAgentJob



SYNOPSIS

Set-DbaAgentJob updates a job.





SYNTAX

Set-DbaAgentJob [[-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>] [[-SqlCredential]

<Pscredential>] [[-Job] <System.Object[]>] [[-Schedule] <System.Object[]>] [[-ScheduleId] <System.Int32[]>]

[[-NewName] <String>] [-Enabled <Switch>] [-Disabled <Switch>] [[-Description] <String>] [[-StartStepId] <Int>]

[[-Category] <String>] [[-OwnerLogin] <String>] [[-EventLogLevel] <System.Object>] [[-EmailLevel] <System.Object>]

[[-NetsendLevel] <System.Object>] [[-PageLevel] <System.Object>] [[-EmailOperator] <String>] [[-NetsendOperator]

<String>] [[-PageOperator] <String>] [[-DeleteLevel] <System.Object>] [-Force <Switch>] [[-InputObject]

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





DESCRIPTION

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





PARAMETERS

-Category [<String>]

The category of the job.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-DeleteLevel [<System.Object>]

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.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Description [<String>]

The description of the job.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Disabled [<Switch>]

Disabled the job



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-EmailLevel [<System.Object>]

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.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-EmailOperator [<String>]

The e-mail name of the operator to whom the e-mail is sent when EmailLevel is reached.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Enabled [<Switch>]

Enabled the job.



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



-EventLogLevel [<System.Object>]

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.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Force [<Switch>]

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



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



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

Enables piping job objects



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Job [<System.Object[]>]

The name of the job.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-NetsendLevel [<System.Object>]

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.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-NetsendOperator [<String>]

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



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-NewName [<String>]

The new name for the job.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-OwnerLogin [<String>]

The name of the login that owns the job.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-PageLevel [<System.Object>]

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.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-PageOperator [<String>]

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



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Schedule [<System.Object[]>]

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



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-ScheduleId [<System.Int32[]>]

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



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 greater.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-StartStepId [<Int>]

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



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: Sander Stad (@sqlstad), sqlstad.nl



Website: https://dbatools.io

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

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



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



RELATED LINKS

https://dbatools.io/Set-DbaAgentJob