commands

^

Set-DbaAgentSchedule

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

 

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 are 1, "Once", 4, "Daily", 8, "Weekly", 16, "Monthly", 32, "MonthlyRelative", 64, "AgentStart", 128 or "IdleComputer"

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

The days that a job is executed Allowed values are 1, "Sunday", 2, "Monday", 4, "Tuesday", 8, "Wednesday", 16, "Thursday", 32, "Friday", 64, "Saturday", 62, "Weekdays", 65, "Weekend", 127, "EveryDay". If 62, "Weekdays", 65, "Weekend", 127, "EveryDay" is used it overwrites any other value that has been passed before.

Alias
Required False
Pipeline false
Default Value
Accepted Values EveryDay,Weekdays,Weekend,Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,62,64,65,127
-FrequencySubdayType

Specifies the units for the subday FrequencyInterval. Allowed values are 1, "Time", 2, "Seconds", 4, "Minutes", 8 or "Hours"

Alias
Required False
Pipeline false
Default Value
Accepted Values 1,Time,2,Seconds,4,Minutes,8,Hours
-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

 

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.