< Back
Set-DbaAgentSchedule
Post
NAME Set-DbaAgentSchedule
SYNOPSIS
Set-DbaAgentSchedule updates a schedule in the msdb database.
SYNTAX
Set-DbaAgentSchedule [-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]> [[-SqlCredential]
<Pscredential>] [-Job] <System.Object[]> [-ScheduleName] <String> [[-NewName] <String>] [-Enabled <Switch>]
[-Disabled <Switch>] [[-FrequencyType] <System.Object>] [[-FrequencyInterval] <Int>] [[-FrequencySubdayType]
<System.Object>] [[-FrequencySubdayInterval] <Int>] [[-FrequencyRelativeInterval] <System.Object>]
[[-FrequencyRecurrenceFactor] <Int>] [[-StartDate] <String>] [[-EndDate] <String>] [[-StartTime] <String>]
[[-EndTime] <String>] [-EnableException <Switch>] [-Force <Switch>] [<CommonParameters>]
DESCRIPTION
Set-DbaAgentSchedule will help update a schedule for a job. It does not attach the schedule to a job.
PARAMETERS
-Disabled [<Switch>]
Set the schedule to disabled.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Enabled [<Switch>]
Set the schedule to 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.
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.
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 [<Int>]
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.
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 8, "Weekly", 16, "Monthly", 32 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).
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 are 1, "Time", 2, "Seconds", 4, "Minutes", 8 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 are 1, "Once", 4, "Daily", 8, "Weekly", 16, "Monthly", 32, "MonthlyRelative", 64, "AgentStart",
128 or "IdleComputer"
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
-NewName [<String>]
The new name for the schedule.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-ScheduleName [<String>]
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.
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.
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:\\>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
RELATED LINKS
https://dbatools.io/Set-DbaAgentSchedule
SYNOPSIS
Set-DbaAgentSchedule updates a schedule in the msdb database.
SYNTAX
Set-DbaAgentSchedule [-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]> [[-SqlCredential]
<Pscredential>] [-Job] <System.Object[]> [-ScheduleName] <String> [[-NewName] <String>] [-Enabled <Switch>]
[-Disabled <Switch>] [[-FrequencyType] <System.Object>] [[-FrequencyInterval] <Int>] [[-FrequencySubdayType]
<System.Object>] [[-FrequencySubdayInterval] <Int>] [[-FrequencyRelativeInterval] <System.Object>]
[[-FrequencyRecurrenceFactor] <Int>] [[-StartDate] <String>] [[-EndDate] <String>] [[-StartTime] <String>]
[[-EndTime] <String>] [-EnableException <Switch>] [-Force <Switch>] [<CommonParameters>]
DESCRIPTION
Set-DbaAgentSchedule will help update a schedule for a job. It does not attach the schedule to a job.
PARAMETERS
-Disabled [<Switch>]
Set the schedule to disabled.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Enabled [<Switch>]
Set the schedule to 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.
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.
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 [<Int>]
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.
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 8, "Weekly", 16, "Monthly", 32 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).
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 are 1, "Time", 2, "Seconds", 4, "Minutes", 8 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 are 1, "Once", 4, "Daily", 8, "Weekly", 16, "Monthly", 32, "MonthlyRelative", 64, "AgentStart",
128 or "IdleComputer"
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
-NewName [<String>]
The new name for the schedule.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-ScheduleName [<String>]
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.
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.
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:\\>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
RELATED LINKS
https://dbatools.io/Set-DbaAgentSchedule