SharePoint Tech Blog

07/08/2009

Execute SharePoint timer job using Powershell

Filed under: SharePoint — Tags: , , — kctnpblog @ 1:20 am

If you are in a situation where you need to test a content expiry policy, the schedule for the out of box timer jobs will need to be changed.
To change the “Hold Processing and Reporting” timer job, you can do this using

stsadm -o setholdschedule -schedule "every 1 minutes between 0 and 59"

To change the “Information management policy” timer job, you can do this using

stsadm -o setpolicyschedule -schedule "every 1 minutes between 0 and 59"

To change the “Records Center Processing” timer job, you can do this using

stsadm -o setrecordsrepositoryschedule -schedule "every 1 minutes between 0 and 59"

The “Expiration policy” timer job however, cannot be set using stsadm. Instead, use this Powershell script to run it manually:
This code requires the SharePoint Powershell Profile to be loaded beforehand…

$farm=[Microsoft.SharePoint.Administration.SPFarm]::Local
foreach ($service in $farm.Services) {
if ($service.TypeName -eq "Microsoft.Office.RecordsManagement.Internal. PolicyConfigService"){
foreach ($jobdefinition in $service.JobDefinitions){
if ($jobdefinition.TypeName -eq "Microsoft.Office.RecordsManagement.Internal. ExpirationJobDefinition"){
$jobdefinition.Execute([Guid]::Empty);
Write-Host "Execution completed";
}
}
}
}

Schedule the above code to run automatically based on a windows timer job once very minute or as often as required on the development/test environment.
It is recommended to run the “Information management policy” timer job before running the “Expiration policy” timer job because the “Information management policy” timer job updates each item that is affected by the policy if the policy has changed.

Advertisements

1 Comment »

  1. SharePoint Development Weekly Roundup (11Aug)…

    TOP THIS WEEK Bad Practice #1: Not using Solutions for d ……

    Trackback by SharePoint Blog by Jeremy Thake in Perth, Australia — 11/08/2009 @ 10:55 am


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: