Wednesday, October 8, 2014

Sitecore PowerShell Run Task On Demand

Recently I needed to help a colleague run a scheduled task on-demand. Immediately I thought to myself, Sitecore PowerShell Extensions can do it! I was certain other developers had created a solution, but I needed something quick.

helped by providing one out-of-the-box way to accomplish the task. The short answer is to use the Task Manager. Have a look under Sitecore -> PowerShell Toolbox -> Task Manager


You are then presented with a delightful screen which provides you with options like Execute Now and Edit Schedule.


 also had a good suggestion. Oh wait, that was me :)

This solution creates a context menu item that can be made visible when selecting an item with the Schedule template.


What we'll do here is create a new PowerShell Script item called Run Task, set a rule on it to only appear for the Schedule template, and write some simple code to run the task:

$item = Get-Item -Path .
if($item) {
  $schedule = Get-TaskSchedule -Item $item
  Start-TaskSchedule -Schedule $schedule
}





You can also confirm that the scheduled task completed successfully by checking the Log Viewer.

(coincidentally with the same last name) did provide a detailed article on an approach that does not the module.
also provided details to a module that provides an alternative experience to the schedule editor.

I hope this helps someone.

// Michael

No comments:

Post a Comment