commands

^

Set-DbaAgentSchedule

Author Sander Stad (@sqlstad, sqlstad.nl)
Availability Windows, Linux, macOS

 

Want to see the source code for this command? Check out Set-DbaAgentSchedule on GitHub.
Want to see the Bill Of Health for this command? Check out Set-DbaAgentSchedule.

Synopsis

Set-DbaAgentSchedule updates a schedule in the msdb database.

Description

Set-DbaAgentSchedule will help update a schedule for a job. It does not attach the schedule to a job.

Syntax

Set-DbaAgentSchedule
    [-SqlInstance] <DbaInstanceParameter[]>
    [[-SqlCredential] <PSCredential>]
    [-Job] <Object[]>
    [-ScheduleName] <String>
    [[-NewName] <String>]
    [-Enabled]
    [-Disabled]
    [[-FrequencyType] <Object>]
    [[-FrequencyInterval] <Object[]>]
    [[-FrequencySubdayType] <Object>]
    [[-FrequencySubdayInterval] <Int32>]
    [[-FrequencyRelativeInterval] <Object>]
    [[-FrequencyRecurrenceFactor] <Int32>]
    [[-StartDate] <String>]
    [[-EndDate] <String>]
    [[-StartTime] <String>]
    [[-EndTime] <String>]
    [-EnableException]
    [-Force]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Set-DbaAgentSchedule -SqlInstance sql1 -Job Job1 -ScheduleName daily -Enabled

Changes the schedule for Job1 with the name 'daily' to enabled

Example: 2
PS C:\> Set-DbaAgentSchedule -SqlInstance sql1 -Job Job1 -ScheduleName daily -NewName weekly -FrequencyType Weekly -FrequencyInterval Monday, Wednesday, Friday

Changes the schedule for Job1 with the name daily to have a new name weekly

Example: 3
PS C:\> Set-DbaAgentSchedule -SqlInstance sql1 -Job Job1, Job2, Job3 -ScheduleName daily -StartTime '230000'

Changes the start time of the schedule for Job1 to 11 PM for multiple jobs

Example: 4
PS C:\> Set-DbaAgentSchedule -SqlInstance sql1, sql2, sql3 -Job Job1 -ScheduleName daily -Enabled

Changes the schedule for Job1 with the name daily to enabled on multiple servers

Example: 5
PS C:\> sql1, sql2, sql3 | Set-DbaAgentSchedule -Job Job1 -ScheduleName daily -Enabled

Changes the schedule for Job1 with the name 'daily' to enabled on multiple servers using pipe line

Required 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 True
Pipeline true (ByValue)
Default Value
-Job

The name of the job that has the schedule.

Alias
Required True
Pipeline true (ByValue)
Default Value
-ScheduleName

The name of the schedule.

Alias
Required True
Pipeline true (ByValue)
Default Value

Optional Parameters

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

The new name for the schedule.

Alias
Required False
Pipeline false
Default Value
-Enabled

Set the schedule to enabled.

Alias
Required False
Pipeline false
Default Value False
-Disabled

Set the schedule to disabled.

Alias
Required False
Pipeline false
Default Value False
-FrequencyType

A value indicating when a job is to be executed.
Allowed values: 'Once', 'OneTime', 'Daily', 'Weekly', 'Monthly', 'MonthlyRelative', 'AgentStart', 'AutoStart', 'IdleComputer', 'OnIdle'
The following synonyms provide flexibility to the allowed values for this function parameter:
Once=OneTime
AgentStart=AutoStart
IdleComputer=OnIdle
If force is used the default will be "Once".

Alias
Required False
Pipeline false
Default Value
Accepted Values Once,OneTime,Daily,Weekly,Monthly,MonthlyRelative,AgentStart,AutoStart,IdleComputer,OnIdle,1,4,8,16,32,64,128
-FrequencyInterval

The days that a job is executed
Allowed values for FrequencyType 'Daily': EveryDay or a number between 1 and 365.
Allowed values for FrequencyType 'Weekly': Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Weekdays, Weekend or EveryDay.
Allowed values for FrequencyType 'Monthly': Numbers 1 to 31 for each day of the month.
If "Weekdays", "Weekend" or "EveryDay" is used it over writes any other value that has been passed before.
If force is used the default will be 1.

Alias
Required False
Pipeline false
Default Value
-FrequencySubdayType

Specifies the units for the subday FrequencyInterval.
Allowed values are 1, 'Once', 'Time', 2, 'Seconds', 'Second', 4, 'Minutes', 'Minute', 8, 'Hours', 'Hour'

Alias
Required False
Pipeline false
Default Value
Accepted Values 1,Once,Time,2,Seconds,Second,4,Minutes,Minute,8,Hours,Hour
-FrequencySubdayInterval

The number of subday type periods to occur between each execution of a job.

Alias
Required False
Pipeline false
Default Value 0
-FrequencyRelativeInterval

A job's occurrence of FrequencyInterval in each month, if FrequencyType is 32 (MonthlyRelative).

Alias
Required False
Pipeline false
Default Value
Accepted Values Unused,First,Second,Third,Fourth,Last
-FrequencyRecurrenceFactor

The number of weeks or months between the scheduled execution of a job. FrequencyRecurrenceFactor is used only if FrequencyType is 8, "Weekly", 16, "Monthly", 32 or "MonthlyRelative".

Alias
Required False
Pipeline false
Default Value 0
-StartDate

The date on which execution of a job can begin.

Alias
Required False
Pipeline false
Default Value
-EndDate

The date on which execution of a job can stop.

Alias
Required False
Pipeline false
Default Value
-StartTime

The time on any day to begin execution of a job. Format HHMMSS / 24 hour clock.
Example: '010000' for 01:00:00 AM.
Example: '140000' for 02:00:00 PM.

Alias
Required False
Pipeline false
Default Value
-EndTime

The time on any day to end execution of a job. Format HHMMSS / 24 hour clock.
Example: '010000' for 01:00:00 AM.
Example: '140000' for 02:00:00 PM.

Alias
Required False
Pipeline false
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
-Force

The force parameter will ignore some errors in the parameters and assume defaults.
It will also remove the any present schedules with the same name for the specific job.

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