Skip to content

Add functionality equivalent to sp_detach_schedule #9687

Open
@ReeceGoding

Description

@ReeceGoding

Summarize Functionality

We have a wealth of cmdlets for managing Agent Job schedules:

  • New-DbaAgentSchedule creates them
  • Remove-DbaAgentSchedule destroys them
  • Set-DbaAgentSchedule updates them at the job level. You can also use it to disable schedules, but I'm fairly sure that SQL Server doesn't support disabling shared schedules for just one job.
  • Set-DbaAgentJob attaches them.

But suppose that I wish detach a schedule from a job. Aside from writing the T-SQL yourself and using Invoke-DbaQuery, I know of no solution to this within dbatools.

The problem that made me discover this issues was as follows:

  • Job A and job B share a schedule.
  • Job A is bugged and must not run until it is fixed
  • Strict rules prevent disabling or deleting job A
  • I could not disable or delete the schedule for job A, because it is shared with job B and I didn't want to damage job B
  • Detaching the shared schedule from job A was allowed, and therefore my only choice

If dbatools has an alternative solution, then I would love to hear it.

Is there a command that is similiar or close to what you are looking for?

Yes

Technical Details

A wrapper for sp_detach_schedule should do it, but I am not totally sure where it should be put. I see three options:

  1. Make a new cmdlet, Remove-DbaAgentJobSchedule.
  2. Add a new parameter to Set-DbaAgentJob, giving a list of schedules to remove.
  3. Add a new parameter to Set-DbaAgentSchedule, giving a switch for something like -Detach.

I do not know if what we want already exists in SMO. I barely trust myself to check. This is the best I found.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featuretriage requiredNew issue that has not been reviewed by maintainers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions