Scheduling jobs with Simply Migrate

Scheduling migration jobs to run at specific times in the past has needed a little be of scripting love, everyone loves scripting (*sic*) but we hear you and we wanted to make this as easy as can be!

From build 4095 – currently in beta, so get it while it’s hot, or just wait for the next release update – the following PowerShell cmd-let’s are available to manage job and batch scheduling.

New-SMSchedule

Use the following to create a new schedule event to be used in one or more jobs or batches.

NAME
    New-SMSchedule

SYNTAX
    New-SMSchedule [[-Type] {OneOff | Recurring}] [-Name ] [-ScheduleWindowStart ]
    [-ScheduleWindowEnd ] [-StartTime ] [-EndTime ] [-Monday] [-Tuesday] [-Wednesday]
    [-Thursday] [-Friday] [-Saturday] [-Sunday] [-JobId ] [-BatchId ]  []


ALIASES
    None


REMARKS
    None

Example 1 – One off schedule

The simplest kind of schedule has only a one-off start date and time, and looks like this:

PS C:\> New-SMSchedule -Name "EndOfMonth" -Type OneOff -ScheduleWindowStart "31/08/2017 18:00"

EntryId             : 30
Type                : OneOff
Name                : EndOfMonth
ScheduleWindowStart : 31/08/2017 18:00:00
ScheduleWindowEnd   :
StartTime           :
EndTime             :
Monday              :
Tuesday             :
Wednesday           :
Thursday            :
Friday              :
Saturday            :
Sunday              :
Links               : {}

In this example we create a OneOff schedule with a ScheduleWindowStart to identify when this schedule will start, we could also supply a ScheduleWindowEnd to specify when this must end.

Example 2 – Weekend schedule

Another common use case is a schedule that will only run on weekends, this can be created like this:

PS C:\> New-SMSchedule -Name "Weekends" -Type Recurring -Saturday -Sunday

EntryId             : 31
Type                : Recurring
Name                : Weekends
ScheduleWindowStart :
ScheduleWindowEnd   :
StartTime           :
EndTime             :
Monday              : False
Tuesday             : False
Wednesday           : False
Thursday            : False
Friday              : False
Saturday            : True
Sunday              : True
Links               : {}

Here we created a recurring schedule event that will be active every Saturday and Sunday for all time, we haven’t specified a Start/End times or ScheduleWindowStart/End date/times but if we could have to be more specific about when during weekends this schedule should be active.

Example 3 – Weeknights after normal working hours only

To prevent a job or batch of jobs from running during business hours, a recurring time based schedule can be created like this:

PS C:\> New-SMSchedule -Name "Weekday evenings" -Type Recurring -StartTime 19:00 -EndTime 06:00 -Monday -Tuesday -Wednesday -Thursday -Friday

EntryId             : 32
Type                : Recurring
Name                : Weekday evenings
ScheduleWindowStart :
ScheduleWindowEnd   :
StartTime           : 19:00:00
EndTime             : 06:00:00
Monday              : True
Tuesday             : True
Wednesday           : True
Thursday            : True
Friday              : True
Saturday            : False
Sunday              : False
Links               : {}

In the final example we have created a recurring schedule for Monday through Friday but only after 19:00 and before 06:00.

Note that if for a particular month you wanted to increase the schedule window, then you could create a copy of the above with the increased time periods (say 17:00 -> 09:00), but include the ScheduleWindowStart and ScheduleWindowEnd dates to indicate that during that special period those longer hours are available.

Note: Jobs and Batches can be linked to many different schedules.

As you can see, using a combination or weekdays, start / end times as well as schedule window start / end allows for great flexibility in defining schedule hours for your jobs.

Get-SMSchedules

Used to view an existing schedule or schedules.

NAME
    Get-SMSchedules

SYNTAX
    Get-SMSchedules [[-ScheduleId] ] [-Type {OneOff | Recurring}] [-JobId ] [-BatchId ]
    []


ALIASES
    None


REMARKS
    None

Example Usage

PS C:\> Get-SMSchedules 32

EntryId             : 32
Type                : Recurring
Name                : Weekday evenings
ScheduleWindowStart :
ScheduleWindowEnd   :
StartTime           : 19:00:00
EndTime             : 06:00:00
Monday              : True
Tuesday             : True
Wednesday           : True
Thursday            : True
Friday              : True
Saturday            : False
Sunday              : False
Links               : {}

Set-SMSchedule

Used to update an existing schedule.

NAME
    Set-SMSchedule

SYNTAX
    Set-SMSchedule [[-ScheduleId] ] [-Schedules <Schedule[]>] [-Type {OneOff | Recurring}] [-Name ]
    [-ScheduleWindowStart ] [-ScheduleWindowEnd ] [-StartTime ] [-EndTime ]
    [-Monday] [-Tuesday] [-Wednesday] [-Thursday] [-Friday] [-Saturday] [-Sunday] [-JobId ] [-BatchId ]
    []


ALIASES
    None


REMARKS
    None

Example 1 – Updating a schedule

PS C:\> Set-SMSchedule 32 -Monday -Tuesday -Wednesday -Thursday

EntryId             : 32
Type                : Recurring
Name                : Weekday evenings
ScheduleWindowStart :
ScheduleWindowEnd   :
StartTime           : 19:00:00
EndTime             : 06:00:00
Monday              : True
Tuesday             : True
Wednesday           : True
Thursday            : True
Friday              : False
Saturday            : False
Sunday              : False
Links               : {}

Here we have changed the working days in this schedule from Mon-Fri to Mon-Thurs.

Example 2 – Adding a schedule to a Job

PS C:\> Set-SMSchedule 32 -Monday -Tuesday -Wednesday -Thursday -JobId 5

EntryId             : 32
Type                : Recurring
Name                :
ScheduleWindowStart :
ScheduleWindowEnd   :
StartTime           : 19:00:00
EndTime             : 06:00:00
Monday              : True
Tuesday             : True
Wednesday           : True
Thursday            : True
Friday              : False
Saturday            : False
Sunday              : False
Links               : {32}

JobId or BatchId can also be used in Set-SMSchedule, but you can also use the normal New-SMJob / Set-SMJob and New-SMBatch / Set-SMBatch cmdlets as below to apply a schedule.

Note: When specifying days of the week, always include ALL the days required when using Set-SMSchedule, or else that day will be excluded.

Remove-SMSchedules

Finally in order to delete previously created schedules use the following:

NAME
    Remove-SMSchedules

SYNTAX
    Remove-SMSchedules [[-ScheduleId] ] [-Schedules <Schedule[]>] [-JobId ] [-BatchId ] [-Force]
    []


ALIASES
    None


REMARKS
    None

Example Usage

PS C:\> Remove-SMSchedules 5

Confirm
Are you sure you want to DELETE this schedule 5?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"):
WARNING: Schedule 5 deleted.

This will completely delete the schedule(s), and remove any existing links to jobs or batches.

Using schedules in Jobs and Batches

To add a schedule to an existing job using Set-SMJob, use the following new option:

PS C:\> Set-SMJob 10 -Schedules 31,33

JobId               : 10
BatchId             : 1
JobStatus           : Processing
StatusMessage       :
Priority            : 10
PercentComplete     : 90
TimeStarted         : 16/11/2016 10:38:47
TimeFinished        : 16/11/2016 10:38:48
SourceMailbox       : C:\Temp\TestUser
TargetMailbox       : FilesMsg
Source              : FilesEml
Target              : FilesMsg
DateFrom            : 01/01/1900 00:00:00
DateTo              : 02/01/2100 00:00:00
ItemsTotal          : 202
ItemsFailed         : 0
ItemsRemaining      : 21
FailedCount         : 0
JobCreatedBy        : nsp
JobModifiedBy       : nsp
JobCreated          : 16/11/2016 10:38:47
JobModified         : 24/08/2017 14:29:52
[...]
Entries             :
Schedules           : {Weekends, Weekday evenings}

As you can see from the new job property Schedules, using we can assign one or more schedules to a given job.

We can do the same for a batch:

PS C:\> Set-SMBatch 1 -Schedules 31,33


BatchId     : 1
BatchName   : Main
CreatedDate : 16/11/2016 21:05:30
Jobs        : {105}
IsActive    : False
InProgress  :
Schedules   : {Weekends, Weekday evenings}

Final Words

With the flexibility of creating schedules and assigning them to one or more jobs or batches, Ie a many to many relationship, it is possible to meet almost any complex scheduling requirement.

 

No Comments

Be the first to start a conversation

Leave a Comment