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.
Set-DbaAgentSchedule updates a schedule in the msdb database.
Set-DbaAgentSchedule will help update a schedule for a job. It does not attach the schedule to a job.
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>]
PS C:\> Set-DbaAgentSchedule -SqlInstance sql1 -Job Job1 -ScheduleName daily -Enabled
Changes the schedule for Job1 with the name 'daily' to enabled
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
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
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
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
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 |
The name of the job that has the schedule.
Alias | |
Required | True |
Pipeline | true (ByValue) |
Default Value |
The name of the schedule.
Alias | |
Required | True |
Pipeline | true (ByValue) |
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 new name for the schedule.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Set the schedule to enabled.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
Set the schedule to disabled.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
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 |
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 |
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 |
The number of subday type periods to occur between each execution of a job.
Alias | |
Required | False |
Pipeline | false |
Default Value | 0 |
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 |
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 |
The date on which execution of a job can begin.
Alias | |
Required | False |
Pipeline | false |
Default Value |
The date on which execution of a job can stop.
Alias | |
Required | False |
Pipeline | false |
Default Value |
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 |
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 |
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 |
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 |
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 |