< Back

New-DbaAgentSchedule

Mon Jan 13, 2020 12:39 pm

NAME New-DbaAgentSchedule



SYNOPSIS

New-DbaAgentSchedule creates a new schedule in the msdb database.





SYNTAX

New-DbaAgentSchedule [-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]> [[-SqlCredential]

<Pscredential>] [[-Job] <System.Object[]>] [[-Schedule] <System.Object>] [-Disabled <Switch>] [[-FrequencyType]

<System.Object>] [[-FrequencyInterval] <System.Object[]>] [[-FrequencySubdayType] <System.Object>]

[[-FrequencySubdayInterval] <Int>] [[-FrequencyRelativeInterval] <System.Object>] [[-FrequencyRecurrenceFactor]

<Int>] [[-StartDate] <String>] [[-EndDate] <String>] [[-StartTime] <String>] [[-EndTime] <String>] [-Force

<Switch>] [-EnableException <Switch>] [<CommonParameters>]





DESCRIPTION

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.





PARAMETERS

-Disabled [<Switch>]

Set the schedule to disabled. Default is enabled



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



-EndDate [<String>]

The date on which execution of a job can stop.



If force is used the end date will be '9999-12-31'



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-EndTime [<String>]

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.



If force is used the start time will be '23:59:59'



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.

It will also remove the any present schedules with the same name for the specific job.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-FrequencyInterval [<System.Object[]>]

The days that a job is executed



Allowed values: Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Weekdays, Weekend or EveryDay.

The other allowed values are the 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.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-FrequencyRecurrenceFactor [<Int>]

The number of weeks or months between the scheduled execution of a job.



FrequencyRecurrenceFactor is used only if FrequencyType is "Weekly", "Monthly" or "MonthlyRelative".



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-FrequencyRelativeInterval [<System.Object>]

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



Allowed values: First, Second, Third, Fourth or Last



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-FrequencySubdayInterval [<Int>]

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



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-FrequencySubdayType [<System.Object>]

Specifies the units for the subday FrequencyInterval.



Allowed values: Time, Seconds, Minutes, or Hours



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-FrequencyType [<System.Object>]

A value indicating when a job is to be executed.



Allowed values: Once, Daily, Weekly, Monthly, MonthlyRelative, AgentStart or IdleComputer



If force is used the default will be "Once".



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Job [<System.Object[]>]

The name of the job that has the schedule.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Schedule [<System.Object>]

The name of the schedule.



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



-StartDate [<String>]

The date on which execution of a job can begin.



If force is used the start date will be the current day



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-StartTime [<String>]

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.



If force is used the start time will be '00:00:00'



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

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:\\>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.

-------------------------- EXAMPLE 2 --------------------------



PS C:\\>New-DbaAgentSchedule -SqlInstance sstad-pc -Schedule MonthlyTest -FrequencyType Monthly -FrequencyInterval

10 -FrequencyRecurrenceFactor 1 -Force



Create a schedule with a monhtly 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.



RELATED LINKS

https://dbatools.io/New-DbaAgentSchedule