# Tasks

The task scheduler is a great way to run scripts in a periodic fashion. You may find the need to automatically archive log files into a compressed file. Perhaps send an email with a generated report based on stale site content.

## Video Tutorial

![Scheduled Task Editor](https://img.youtube.com/vi/Q6QKqRwrkuU/0.jpg)

[Click for a demo](https://www.youtube.com/watch?v=Q6QKqRwrkuU)

## Scheduled Task Command

To help make the setup simple, we've provided a *Task Command*.

![PowerShell Script Command](https://165468320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LA37Eh9vuWwQHUTc2NT%2Fuploads%2Fgit-blob-4b56df346f9d426ef4f1c2d19d0dc8a9e5c40e36%2Ftasks-powershellscriptcommand.png?alt=media)

The command shown above is simply a type exposed as a public method in the *Spe* assembly. There exists an update method which accepts one or more items and executes the associated script.

Beneath *Schedules* you can create as many tasks as Sitecore will allow. Configure the *Command* and *Items* fields like that shown below.

![PowerShell Script Task](https://165468320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LA37Eh9vuWwQHUTc2NT%2Fuploads%2Fgit-blob-dae1c454c3ae967b0c33bf58240858d5b101b12c%2Ftasks-archiveschedule.png?alt=media)

The *Items* field contains the path to a script in the *Script Library*.

Below are some of the scripts found out-of-the-box with SPE.

| Module                  | Script                                                           |
| ----------------------- | ---------------------------------------------------------------- |
| System Maintenance      | Archive Sitecore logs, Clean up deleted items older than 30 days |
| User Session Management | Remove idle user sessions                                        |

## Create and Manage Tasks

We've added a context menu item to provide you with a shortcut to the Task Scheduler Editor.

Create a new scheduled task:

![Insert Option for Task](https://165468320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LA37Eh9vuWwQHUTc2NT%2Fuploads%2Fgit-blob-48fb2ebde2f981bcc79974df00d5804e7741f65f%2Ftask-inserttask.png?alt=media)

Run or edit the scheduled task:

![Run or Edit Task Schedule](https://165468320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LA37Eh9vuWwQHUTc2NT%2Fuploads%2Fgit-blob-fe7ed64384042ff78984d747fb7df1d52c49e104%2Ftask-runedittask.png?alt=media)

The scheduled task is capable of running 1-to-many scripts. Choose all that apply for the selected task. Each script runs within a shared session, making it possible to share results between scripts.

**Note:** Make use of the **Enable Rule** to take advantage of the rules engine.

![Dialog to Select Task Scripts](https://165468320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LA37Eh9vuWwQHUTc2NT%2Fuploads%2Fgit-blob-69aab15a49257a9299b35863cdc53117d7271296%2Ftask-createtaskwithscripts.png?alt=media)

The task schedule has an intuitive dialog for working with and changing the frequency.

![Dialog to Edit Task Schedule](https://165468320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LA37Eh9vuWwQHUTc2NT%2Fuploads%2Fgit-blob-1690f269977da718baf3d2b783d4af80961c4c69%2Ftask-edittaskschedule.png?alt=media)

**Note:** Examples included are in the following modules

* License Expiration
* Media Library Maintenance
* System Maintenance

See how Adam added [powershell driven Sitecore scheduled tasks](https://github.com/SitecorePowerShell/Book/tree/a1cbd06eba0aad8913e553f4aaa08de0412c635a/modules/integration-points/tasks/\[https:/blog.najmanowicz.com/2011/11/29/powershell-driven-sitecore-scheduled-tasks/]/README.md).
