So now that you can easily create the menus and ribbons executing PowerShell scripts, it might be a good time to do some more administrative tasks? let?s start with scheduled tasks. I?m not going to go deep into the task scheduling, you can find an excellent post by John West on his blog regarding task scheduling. Currently the PowerShell module supports one of the ways described in the post ? the section describing how to configure them is called ?Scheduled Tasks? in the blog.

The module comes with an out-of-the-box PowerShell script command as you can see


You don?t need to create any additional commands, instead you only need to create a script and a schedule for it and the existing command will handle all of them. In my example I wanted to trim all recycle bin items every night.

Let?s get cracking?

First you need a script that will accomplish the task. The module automatically creates a Scripts folder in the following location: /sitecore/system/Modules/Scripts/. It probably is best if you stick to putting your scripts there. The Insert options for it are limited to scripts and folders so you can organize your scripts into subfolders if the number will grow significantly.

In my case the script part will be fairly simple:


The Popup window and Pre-execution warning settings in this case have no meaning as the script has no means of providing this kind of feedback as it?s executed in a background thread.

Now create a schedule for your script in /sitecore/system/Tasks/Schedules/:


I strongly encourage that you read more about how task scheduling works in Johns blog. An additional feature you might find useful since there is no UI component to running scheduled tasks is the new Write-Log commandlet, which wors similarly to Write-Host but instead writes to Sitecore diagnostic logs. The syntax is as follows

Write-Log [[-Object] <Object>] [-Separator <Object>] 
  [-Log <LogNotificationLevel>]

So for example to write an info message you can use:

Write-Log ?Recycle bin clear scheduled task started?

Similarly you can write a Debug message like:

Write-Log ?Log Debug ?This is a debug message?

This supports all of the common log types like: Debug, Error, Fatal, Warning & Info ? if no log type specified ? Info will be used.

The solution requires the latest Sitecore PowerShell Console (1.2.0) from Cognifide, available for free from Sitecore Shared Source site.

All feedback appreciated!

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

This entry (Permalink) was posted on Tuesday, November 29th, 2011 at 5:21 pm and is filed under Uncategorized. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response , or trackback from your own site.