Thor Logo dbatools

Get-DbaAgentSchedule

View Source
Chris McKeown (@devopsfu), devopsfu.com
Windows, Linux, macOS

Synopsis

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.

PropertyValue
Alias
RequiredTrue
Pipelinetrue (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.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
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.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
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.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
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.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
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.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default ValueFalse