---
title: "New-DbaAgentSchedule"
description: "Creates a new SQL Server Agent schedule for automated job execution"
url: "https://dbatools.io/New-DbaAgentSchedule/"
availability: "Windows, Linux, macOS"
tags: ["Agent", "Job", "JobStep"]
author: "Sander Stad (@sqlstad), sqlstad.nl"
source: "https://github.com/dataplat/dbatools/blob/master/public/New-DbaAgentSchedule.ps1"
last_updated: "2024-01-01"
---

# New-DbaAgentSchedule

## Synopsis

Creates a new SQL Server Agent schedule for automated job execution

## Description

Creates a new schedule in the msdb database that defines when SQL Server Agent jobs should execute. Schedules can be created as standalone objects or immediately attached to existing jobs, allowing you to standardize timing across multiple jobs without recreating the same schedule repeatedly. This replaces the need to manually create schedules through SQL Server Management Studio or T-SQL, while providing comprehensive validation of schedule parameters and frequency options. Supports all SQL Server Agent scheduling options including one-time, daily, weekly, monthly, and relative monthly frequencies with full control over start/end dates, times, and recurrence patterns.

## Syntax

```powershell
New-DbaAgentSchedule
    [-SqlInstance] <DbaInstanceParameter[]>
    [[-SqlCredential] <PSCredential>]
    [[-Job] <Object[]>]
    [[-Schedule] <Object>]
    [-Disabled]
    [[-FrequencyType] <Object>]
    [[-FrequencyInterval] <Object[]>]
    [[-FrequencySubdayType] <Object>]
    [[-FrequencySubdayInterval] <Int32>]
    [[-FrequencyRelativeInterval] <Object>]
    [[-FrequencyRecurrenceFactor] <Int32>]
    [[-FrequencyText] <String>]
    [[-StartDate] <String>]
    [[-EndDate] <String>]
    [[-StartTime] <String>]
    [[-EndTime] <String>]
    [[-Owner] <String>]
    [-Force]
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

```

## Examples

### Example 1: Creates a schedule that runs jobs every day at 6 in the morning

```powershell
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.  

### Example 2: Creates a schedule with a daily frequency every day

```powershell
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 3: Create a schedule with a monthly frequency occuring every 10th of the month

```powershell
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.  

### Example 4: Create a schedule that will run jobs once a week on Sunday @ 1:00AM

```powershell
PS C:\> New-DbaAgentSchedule -SqlInstance sstad-pc -Schedule RunWeekly -FrequencyType Weekly -FrequencyInterval Sunday -StartTime 010000 -Force
```

### Example 5: Create a schedule with the name &quot;Every sunday at 02:00:00&quot; that will run jobs once a week on Sunday @ 2:00AM

```powershell
PS C:\> New-DbaAgentSchedule -SqlInstance sstad-pc -FrequencyText 'Every sunday at 02:00:00'
```

### Example 6: SqlInstance = &quot;sql01&quot; Schedule = &quot;HourlyBusinessHours&quot; FrequencyType = &quot;Daily&quot; FrequencySubdayType = &quot;Hours&quot;...

```powershell
PS C:\> $splatSchedule = @{
PS C:\> New-DbaAgentSchedule @splatSchedule
```

SqlInstance             = "sql01"  
Schedule                = "HourlyBusinessHours"  
FrequencyType           = "Daily"  
FrequencySubdayType     = "Hours"  
FrequencySubdayInterval = 1  
StartTime               = "080000"  
EndTime                 = "170000"  
Force                   = $true  
}  
Creates a schedule that runs every hour between 8:00 AM and 5:00 PM. Jobs using this schedule execute at 8 AM, 9 AM, 10 AM, etc., stopping at 5 PM.  

### Example 7: SqlInstance = &quot;sql01&quot; Schedule = &quot;EveryFiveMinutes&quot; FrequencyType = &quot;Daily&quot; FrequencySubdayType = &quot;Minutes&quot;...

```powershell
PS C:\> $splatSchedule = @{
PS C:\> New-DbaAgentSchedule @splatSchedule
```

SqlInstance             = "sql01"  
Schedule                = "EveryFiveMinutes"  
FrequencyType           = "Daily"  
FrequencySubdayType     = "Minutes"  
FrequencySubdayInterval = 5  
Force                   = $true  
}  
Creates a schedule that runs every 5 minutes throughout the day. Useful for frequent monitoring jobs that need to check system health regularly.  

### Example 8: SqlInstance = &quot;sql01&quot; Schedule = &quot;TwiceDaily&quot; FrequencyType = &quot;Daily&quot; FrequencySubdayType = &quot;Hours&quot;...

```powershell
PS C:\> $splatSchedule = @{
PS C:\> New-DbaAgentSchedule @splatSchedule
```

SqlInstance = "sql01"  
Schedule    = "TwiceDaily"  
FrequencyType           = "Daily"  
FrequencySubdayType     = "Hours"  
FrequencySubdayInterval = 12  
StartTime               = "060000"  
Force                   = $true  
}  
Creates a schedule that runs twice per day at 6:00 AM and 6:00 PM. The 12-hour interval ensures jobs execute exactly twice daily.  

### Example 9: SqlInstance = &quot;sql01&quot; Schedule = &quot;FirstMondayOfMonth&quot; FrequencyType = &quot;MonthlyRelative&quot; FrequencyInterval =...

```powershell
PS C:\> $splatSchedule = @{
PS C:\> New-DbaAgentSchedule @splatSchedule
```

SqlInstance               = "sql01"  
Schedule                  = "FirstMondayOfMonth"  
FrequencyType             = "MonthlyRelative"  
FrequencyInterval         = "Monday"  
FrequencyRelativeInterval = "First"  
FrequencyRecurrenceFactor = 1  
StartTime                 = "020000"  
Force                     = $true  
}  
Creates a schedule that runs on the first Monday of every month at 2:00 AM. Perfect for monthly maintenance tasks that should run on a specific weekday.  

### Example 10: SqlInstance = &quot;sql01&quot; Schedule = &quot;MaintenanceWindow&quot; FrequencyType = &quot;Weekly&quot; FrequencyInterval = &quot;Saturday&quot;...

```powershell
PS C:\> $splatSchedule = @{
PS C:\> New-DbaAgentSchedule @splatSchedule
```

SqlInstance = "sql01"  
Schedule    = "MaintenanceWindow"  
FrequencyType = "Weekly"  
FrequencyInterval = "Saturday", "Sunday"  
StartTime   = "220000"  
EndTime     = "060000"  
StartDate   = "20250101"  
EndDate     = "20251231"  
Force       = $true  
}  
Creates a schedule for weekend maintenance windows running Saturday and Sunday nights from 10:00 PM to 6:00 AM. The schedule is active only during 2025.  

### Example 11: SqlInstance = &quot;sql01&quot; Schedule = &quot;PreprodRefresh&quot; Disabled = $true FrequencyType = &quot;Weekly&quot; FrequencyInterval...

```powershell
PS C:\> $splatSchedule = @{
PS C:\> New-DbaAgentSchedule @splatSchedule
```

SqlInstance = "sql01"  
Schedule    = "PreprodRefresh"  
Disabled    = $true  
FrequencyType = "Weekly"  
FrequencyInterval = "Sunday"  
StartTime   = "040000"  
Force       = $true  
}  
Creates a disabled schedule for pre-production database refreshes. The schedule is configured but won't execute until manually enabled, allowing you to prepare schedules in advance.  

### Example 12: SqlInstance = &quot;sql01&quot; Job = &quot;BackupUserDatabases&quot;, &quot;CheckDBIntegrity&quot;, &quot;UpdateStatistics&quot; Schedule =...

```powershell
PS C:\> $splatSchedule = @{
PS C:\> New-DbaAgentSchedule @splatSchedule
```

SqlInstance = "sql01"  
Job         = "BackupUserDatabases", "CheckDBIntegrity", "UpdateStatistics"  
Schedule    = "NightlyMaintenance"  
FrequencyType = "Daily"  
StartTime   = "010000"  
Force       = $true  
}  
Creates a schedule and immediately attaches it to three different jobs. This demonstrates how to apply a single schedule to multiple jobs in one command.  

### Example 13: SqlInstance = &quot;sql01&quot; Schedule = &quot;QuarterEndReports&quot; FrequencyType = &quot;Monthly&quot; FrequencyInterval = 31...

```powershell
PS C:\> $splatSchedule = @{
PS C:\> New-DbaAgentSchedule @splatSchedule
```

SqlInstance = "sql01"  
Schedule    = "QuarterEndReports"  
FrequencyType = "Monthly"  
FrequencyInterval = 31  
FrequencyRecurrenceFactor = 3  
StartTime   = "180000"  
Owner       = "DOMAIN\SQLServiceAccount"  
Force       = $true  
}  
Creates a schedule that runs every 3 months on the 31st (or last day of month) at 6:00 PM. The Owner parameter specifies which account owns the schedule for permission management.  

### Example 14: SqlInstance = &quot;sql01&quot; Schedule = &quot;BusinessHoursEvery30Min&quot; FrequencyType = &quot;Daily&quot; FrequencySubdayType =...

```powershell
PS C:\> $splatSchedule = @{
PS C:\> New-DbaAgentSchedule @splatSchedule
```

SqlInstance = "sql01"  
Schedule    = "BusinessHoursEvery30Min"  
FrequencyType           = "Daily"  
FrequencySubdayType     = "Minutes"  
FrequencySubdayInterval = 30  
StartTime               = "083000"  
EndTime                 = "173000"  
Force                   = $true  
}  
Creates a schedule that runs every 30 minutes during business hours (8:30 AM to 5:30 PM). First execution is at 8:30 AM, last execution at 5:00 PM.  

### 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.

| Property | Value |
| --- | --- |
| 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.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -Job

Specifies existing SQL Server Agent jobs to immediately attach this schedule to after creation.  
Use this when you want to apply the same schedule to multiple jobs without manually attaching it later through SSMS.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -Schedule

The name for the new schedule that will appear in SQL Server Agent.  
Choose descriptive names like "DailyAt6AM" or "WeeklyMaintenanceWindow" to make schedule management easier for your team.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -Disabled

Creates the schedule in a disabled state, preventing any attached jobs from running until the schedule is manually enabled.  
Use this when you need to set up schedules in advance but don't want them active immediately.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value | False |

##### -FrequencyType

Determines the basic execution pattern for jobs using this schedule.  
Daily runs every day or every N days, Weekly runs on specific days of the week, Monthly runs on specific dates, and MonthlyRelative runs on relative dates like "first Monday."  
Once/OneTime creates single-execution schedules, while AgentStart/AutoStart and IdleComputer/OnIdle create event-triggered schedules.  
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".

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |
| Accepted Values | Once,OneTime,Daily,Weekly,Monthly,MonthlyRelative,AgentStart,AutoStart,IdleComputer,OnIdle |

##### -FrequencyInterval

Defines which specific days the job executes based on the FrequencyType selected.  
For Daily: use numbers 1-365 for "every N days" or "EveryDay" for daily execution.  
For Weekly: specify day names like "Monday,Friday" or use "Weekdays," "Weekend," or "EveryDay."  
For Monthly: use numbers 1-31 to run on specific dates of each month.  
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.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -FrequencySubdayType

Sets the time interval unit when jobs need to run multiple times per day.  
Use "Once" for single daily execution, "Hours" for hourly intervals, "Minutes" for minute-based intervals, or "Seconds" for very frequent execution.  
Most maintenance jobs use "Once" while monitoring jobs might use "Minutes" or "Hours."  
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

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |
| Accepted Values | Once,Time,Seconds,Second,Minutes,Minute,Hours,Hour |

##### -FrequencySubdayInterval

Specifies how often the job repeats within a day when FrequencySubdayType is not "Once."  
For example, with FrequencySubdayType "Hours" and FrequencySubdayInterval 4, the job runs every 4 hours.  
Minimum interval is 10 seconds for second-based scheduling.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value | 0 |

##### -FrequencyRelativeInterval

Determines which occurrence of a day type to use for MonthlyRelative schedules.  
Use "First" for first occurrence, "Second" for second occurrence, etc., or "Last" for the final occurrence of that day in the month.  
For example, "Second" with "Friday" runs on the second Friday of each month.  
Allowed values: First, Second, Third, Fourth or Last

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |
| Accepted Values | Unused,First,Second,Third,Fourth,Last |

##### -FrequencyRecurrenceFactor

Controls how many weeks or months to skip between executions for Weekly, Monthly, and MonthlyRelative schedules.  
Use 1 for every week/month, 2 for every other week/month, 3 for every third, etc.  
This allows schedules like "every 2 weeks on Monday" or "every 3 months on the 15th."  
FrequencyRecurrenceFactor is used only if FrequencyType is "Weekly", "Monthly" or "MonthlyRelative".

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value | 0 |

##### -FrequencyText

Describe common frequencies as a text. Sample text:  
Every minute  
Every 5 minutes  
Every 10 minutes starting at 00:02:30  
Every hour  
Every 2 hours  
Every 4 hours starting at 02:00:00  
Every day at 05:00:00  
Every sunday at 02:00:00  
This is the used regex: every(\s+(?<interval>\d+))?\s+(?<unit>minute|hour|day|sunday|monday|tuesday|wednesday|thursday|friday|saturday)s?(\s+starting)?(\s+at\s+(?<start>\d\d:\d\d:\d\d))?  
If parameter Schedule is not provided, the FrequencyText will be used as the name of the schedule.  
Parameter Force will be set to $true.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -StartDate

The earliest date this schedule can execute jobs, formatted as yyyyMMdd (e.g., "20240315" for March 15, 2024).  
Use this to delay schedule activation until a future date or to document when recurring maintenance should begin.  
With -Force, defaults to today's date.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -EndDate

The latest date this schedule can execute jobs, formatted as yyyyMMdd (e.g., "20241231" for December 31, 2024).  
Use this for temporary schedules or to automatically deactivate seasonal jobs.  
With -Force, defaults to "99991231" (no expiration).

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -StartTime

The time of day when job execution can begin, formatted as HHmmss in 24-hour format (e.g., "143000" for 2:30 PM).  
For subday schedules, this is when the first execution occurs each day.  
With -Force, defaults to "000000" (midnight).

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -EndTime

The time of day when job execution must stop, formatted as HHmmss in 24-hour format (e.g., "180000" for 6:00 PM).  
For subday schedules, no new executions start after this time, but running jobs can complete.  
With -Force, defaults to "235959" (one second before midnight).

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -Owner

The SQL Server login that owns this schedule, which determines permissions for schedule modification.  
Defaults to the login running this command, but you can specify a service account or DBA login for centralized schedule management.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -Force

Bypasses parameter validation and applies default values for missing required parameters like dates and times.  
Also removes any existing schedule with the same name before creating the new one, preventing naming conflicts.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value | False |

##### -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.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value | False |

##### -WhatIf

Shows what would happen if the command were to run. No actions are actually performed.

| Property | Value |
| --- | --- |
| Alias | wi |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -Confirm

Prompts you for confirmation before executing any changing operations within the command.

| Property | Value |
| --- | --- |
| Alias | cf |
| Required | False |
| Pipeline | false |
| Default Value |  |

## Outputs

**Microsoft.SqlServer.Management.Smo.Agent.JobSchedule**

Returns the newly created SQL Server Agent schedule object. When the -Job parameter is specified, the schedule is attached to the specified jobs before being returned.

**Default display properties (via Select-DefaultView):**

- ComputerName: The computer name of the SQL Server instance
- InstanceName: The SQL Server instance name
- SqlInstance: The full SQL Server instance name (computer\instance)
- Name: The name of the schedule
- IsEnabled: Boolean indicating if the schedule is enabled
- FrequencyTypes: The frequency type (Once, Daily, Weekly, Monthly, etc.)
- NextRunDate: DateTime of the next scheduled execution
- LastRunDate: DateTime of the last scheduled execution

**Additional properties available from the SMO JobSchedule object include:**

- FrequencyInterval: The frequency interval value
- FrequencySubDayTypes: The subday frequency type (Once, Hours, Minutes, Seconds)
- FrequencySubDayInterval: The subday frequency interval
- FrequencyRelativeIntervals: The relative interval for monthly relative schedules
- FrequencyRecurrenceFactor: How often the schedule repeats (weeks or months)
- ActiveStartDate: The date when the schedule becomes active
- ActiveEndDate: The date when the schedule stops being active
- ActiveStartTimeOfDay: The time when the schedule starts each day
- ActiveEndTimeOfDay: The time when the schedule stops each day
- OwnerLoginName: The login that owns the schedule
- DateCreated: DateTime when the schedule was created
- ID: Unique identifier for the schedule
- ScheduleUid: Unique GUID for the schedule
All properties from the base SMO JobSchedule object are accessible using Select-Object *.

---

Part of [dbatools](https://dbatools.io/), a free and open source PowerShell module for SQL Server administration. Full command index: https://dbatools.io/commands/
