Author | Sander Stad (@sqlstad), sqlstad.nl |
Availability | Windows, Linux, macOS |
Want to see the source code for this command? Check out New-DbaAgentSchedule on GitHub.
Want to see the Bill Of Health for this command? Check out New-DbaAgentSchedule.
New-DbaAgentSchedule creates a new schedule in the msdb database.
New-DbaAgentSchedule will help create a new schedule for a job.
If the job parameter is not supplied the schedule will not be attached to a job.
New-DbaAgentSchedule
[-SqlInstance] <DbaInstanceParameter[]>
[[-SqlCredential] <PSCredential>]
[[-Job] <Object[]>]
[[-Schedule] <Object>]
[-Disabled]
[[-FrequencyType] <Object>]
[[-FrequencyInterval] <Object[]>]
[[-FrequencySubdayType] <Object>]
[[-FrequencySubdayInterval] <Int32>]
[[-FrequencyRelativeInterval] <Object>]
[[-FrequencyRecurrenceFactor] <Int32>]
[[-StartDate] <String>]
[[-EndDate] <String>]
[[-StartTime] <String>]
[[-EndTime] <String>]
[[-Owner] <String>]
[-Force]
[-EnableException]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
PS C:\> New-DbaAgentSchedule -SqlInstance sql01 -Schedule DailyAt6 -FrequencyType Daily -StartTime "060000" -Force
Creates a schedule that runs jobs every day at 6 in the morning. It assumes default values for the start date, start time, end date and end time due to -Force.
PS C:\> New-DbaAgentSchedule -SqlInstance localhost\SQL2016 -Schedule daily -FrequencyType Daily -FrequencyInterval Everyday -Force
Creates a schedule with a daily frequency every day. It assumes default values for the start date, start time, end date and end time due to -Force.
PS C:\> New-DbaAgentSchedule -SqlInstance sstad-pc -Schedule MonthlyTest -FrequencyType Monthly -FrequencyInterval 10 -FrequencyRecurrenceFactor 1 -Force
Create a schedule with a monthly frequency occuring every 10th of the month. It assumes default values for the start date, start time, end date and end time due to -Force.
PS C:\> New-DbaAgentSchedule -SqlInstance sstad-pc -Schedule RunWeekly -FrequencyType Weekly -FrequencyInterval Sunday -StartTime 010000 -Force
Create a schedule that will run jobs once a week on Sunday @ 1:00AM
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 |
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 name of the job that has the schedule.
Alias | |
Required | False |
Pipeline | false |
Default Value |
The name of the schedule.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Set the schedule to disabled. Default is enabled
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 |
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: 'Once', 'Time', 'Seconds', 'Second', 'Minutes', 'Minute', 'Hours', 'Hour'
The following synonyms provide flexibility to the allowed values for this function parameter:
Once=Time
Seconds=Second
Minutes=Minute
Hours=Hour
Alias | |
Required | False |
Pipeline | false |
Default Value | |
Accepted Values | Once,Time,Seconds,Second,Minutes,Minute,Hours,Hour |
The number of subday type periods to occur between each execution of a job.
The interval needs to be at least 10 seconds long.
Alias | |
Required | False |
Pipeline | false |
Default Value | 0 |
A job's occurrence of FrequencyInterval in each month, if FrequencyInterval is 32 (monthlyrelative).
Allowed values: First, Second, Third, Fourth or Last
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 "Weekly", "Monthly" or "MonthlyRelative".
Alias | |
Required | False |
Pipeline | false |
Default Value | 0 |
The date on which execution of a job can begin. Must be a string in the format yyyyMMdd.
If force is used the start date will be the current day
Alias | |
Required | False |
Pipeline | false |
Default Value |
The date on which execution of a job can stop. Must be a string in the format yyyyMMdd.
If force is used the end date will be '99991231'
Alias | |
Required | False |
Pipeline | false |
Default Value |
The time on any day to begin execution of a job. Must be a string in the format HHmmss / 24 hour clock.
Example: '010000' for 01:00:00 AM.
Example: '140000' for 02:00:00 PM.
If force is used the start time will be '000000' for midnight.
Alias | |
Required | False |
Pipeline | false |
Default Value |
The time on any day to end execution of a job. Must be a string in the format HHmmss / 24 hour clock.
Example: '010000' for 01:00:00 AM.
Example: '140000' for 02:00:00 PM.
If force is used the end time will be '235959' for one second before midnight.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Login to own the job, defaults to login running the command.
Alias | |
Required | False |
Pipeline | false |
Default Value |
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 |
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 |
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 |