Get-DbaAgentSchedule
View SourceSynopsis
Retrieves SQL Agent shared schedules with detailed timing and recurrence information.
Description
Retrieves all shared schedules from SQL Server Agent along with human-readable descriptions of their timing patterns. These shared schedules can be reused across multiple jobs to standardize maintenance windows and reduce schedule management overhead. The function provides filtering options by schedule name, unique identifier, or numeric ID, making it useful for schedule auditing, documentation, and troubleshooting automated job execution patterns.
Syntax
Get-DbaAgentSchedule
[-SqlInstance] <DbaInstanceParameter[]>
[[-SqlCredential] <PSCredential>]
[[-Schedule] <String[]>]
[[-ScheduleUid] <String[]>]
[[-Id] <Int32[]>]
[-EnableException]
[<CommonParameters>]
Examples
Example: 1
PS C:\> Get-DbaAgentSchedule -SqlInstance localhost
Returns all SQL Agent Shared Schedules on the local default SQL Server instance
Example: 2
PS C:\> Get-DbaAgentSchedule -SqlInstance localhost, sql2016
Returns all SQL Agent Shared Schedules for the local and sql2016 SQL Server instances
Example: 3
PS C:\> Get-DbaAgentSchedule -SqlInstance localhost, sql2016 -Id 3
Returns the SQL Agent Shared Schedules with the Id of 3
Example: 4
PS C:\> Get-DbaAgentSchedule -SqlInstance localhost, sql2016 -ScheduleUid 'bf57fa7e-7720-4936-85a0-87d279db7eb7'
Returns the SQL Agent Shared Schedules with the UID
Example: 5
PS C:\> Get-DbaAgentSchedule -SqlInstance sql2016 -Schedule "Maintenance10min","Maintenance60min"
Returns the “Maintenance10min” & “Maintenance60min” schedules from the sql2016 SQL Server instance
Required Parameters
-SqlInstance
The target SQL Server instance or instances. This can be a collection and receive pipeline input to allow the function to be executed against multiple SQL Server instances.
| 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 |
-Schedule
Specifies one or more schedule names to retrieve from the SQL Agent shared schedules collection.
Use this when you need to examine specific schedules by their display names, such as checking timing details for maintenance windows or job execution patterns.
Accepts multiple schedule names and supports wildcards for pattern matching.
| Property | Value |
|---|---|
| Alias | |
| Required | False |
| Pipeline | false |
| Default Value |
-ScheduleUid
Specifies the GUID-based unique identifier of one or more shared schedules to retrieve.
Use this when you need to target schedules by their immutable identifiers, particularly useful for automation scripts or when schedule names might change.
Each shared schedule has a persistent UID that remains constant even if the schedule is renamed.
| Property | Value |
|---|---|
| Alias | |
| Required | False |
| Pipeline | false |
| Default Value |
-Id
Specifies the numeric identifier of one or more shared schedules to retrieve from SQL Agent.
Use this when you know the internal ID numbers of specific schedules, often obtained from previous queries or database system tables.
Schedule IDs are assigned sequentially by SQL Server and remain constant unless the schedule is deleted and recreated.
| Property | Value |
|---|---|
| Alias | |
| Required | False |
| Pipeline | false |
| Default Value |
-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 |
Outputs
Microsoft.SqlServer.Management.Smo.SharedSchedule
Returns one SharedSchedule object per shared schedule found. Shared schedules can be reused across multiple SQL Server Agent jobs to standardize maintenance windows and reduce administrative overhead.
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)
- ScheduleName: The display name of the shared schedule
- ActiveStartDate: The date when the schedule becomes active (format depends on system locale)
- ActiveStartTimeOfDay: The time of day when the schedule becomes active
- ActiveEndDate: The date when the schedule stops being active (year 9999 indicates no end date)
- ActiveEndTimeOfDay: The time of day when the schedule stops being active
- DateCreated: Timestamp when the schedule was created in SQL Agent
- FrequencyTypes: How often the schedule runs (Once, Daily, Weekly, Monthly, MonthlyRelative, AutoStart, OnIdle)
- FrequencyInterval: The interval at which the schedule recurs (meaning depends on FrequencyTypes)
- FrequencySubDayTypes: How often within a day the schedule runs (None, Once, Seconds, Minutes, Hours)
- FrequencySubDayInterval: The interval in seconds, minutes, or hours between executions
- FrequencyRecurrenceFactor: The number of periods between schedule executions (e.g., 2 for every 2 weeks)
- FrequencyRelativeIntervals: Relative position for monthly schedules (First, Second, Third, Fourth, Last)
- IsEnabled: Boolean indicating whether the schedule is active and available for job execution
- JobCount: Number of SQL Server Agent jobs currently using this shared schedule
- ScheduleUid: The unique GUID identifier for this schedule (immutable even if schedule is renamed)
- Description: Human-readable description of the schedule timing pattern (auto-generated from frequency settings)
Additional properties available from the SMO SharedSchedule object:
- Id: Numeric identifier for the shared schedule (assigned sequentially by SQL Server)
- Name: Display name of the shared schedule
- Owner: Login name that owns the schedule All properties from the base SMO object are accessible using Select-Object *, even though only default properties are displayed without explicit selection.
dbatools