CHUVASH.eu

CHunky Universe of Vigouros Astonishing SHarepoint :)

Install a custom timer job in Powershell

First we have to create a class for our timer job which inherits SPTimerJobDefinition, build it and deploy it.

public class TakanaTimer : SPJobDefinition
{
	public TakanaTimer(){}
	public TakanaTimer(string jobName, SPService service,
		SPServer server, SPJobLockType targetType)
		: base(jobName, service, server, targetType) { }

	public TakanaTimer(string jobName, SPWebApplication webapp)
		: base(jobName, webapp, null, SPJobLockType.ContentDatabase)
	{
		Title = jobName;
	}
	public override void Execute(Guid contentDbId)
	{
		Log.Info("Running Takana Timer");
	}
}

There is a powershell example for this, but it has not been updated since MOSS.

In Powershell we need to load our custom assembly into powershell session:

[Reflection.Assembly]::LoadWithPartialName("Takana.Sharepoint.Timer")
$app = get-spwebapplication http://takana
$name = "takana-timer"
$job = new-object Takana.Sharepoint.Timer.Takana($name, $app)
$job.Schedule = [Microsoft.SharePoint.SPSchedule]::FromString("Every 15 minutes between 0 and 59")
$job.update()
#must restart timer service
restart-service sptimerv4

The cool thing here is also that we can create schedule from a text. The code is partially inspired by maraboustork

To remove a Timer Job, get the id of your timer job and run stsadm:

#Get the GUID of the timer job definition with the following cmdlet:
get-sptimerjob | sort-object -property Name | ft Name, Id
stsadm.exe -o deleteconfigurationobject -id

Or even better:

Get-SPTimerJob | where { $_.name -like “**” } |ft id,name
#Set job to a variable
$job = Get-SPTimerJob -id
#And delete it.
$job.Delete()

By the way, the whole list of ootb timers.

About these ads

One response to “Install a custom timer job in Powershell

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

Discovering SharePoint

And having fun doing it

Bram de Jager's SharePoint blog

My view and thoughts on SharePoint.

My programming life

and everything in between

SharePoint Development Lab by @avishnyakov

It is a good place to share some SharePoint stories and development practices.

SharePoint Dragons

Nikander & Margriet on SharePoint

The Zuul Cat Idea Brewery

Where ideas on software development and entrepreneurship brew.

Paul J. Swider

Inspire! Teach! Awe!

Mai Omar Desouki - Avid SharePointer

Egyptian & Vodafoner - Senior SharePoint Consultant

Alexander Ahrens

MCPD | SharePoint | Web Development | JavaScript | .NET

Cameron Dwyer | SharePoint, Outlook, OnePlaceMail

OnePlaceMail, SharePoint, Outlook & Life's Other Little Wonders

.:paul.tavares:.

Me and My doings!

Share SharePoint Points

By Mohit Vashishtha

Jimmy Janlén "Den Scrummande Konsulten"

Erfarenheter, synpunkter och raljerande om Scrum från Jimmy Janlén

SPJoel

SharePoint for everyone

SharePointRyan.com

Ryan Dennis is a SharePoint Solutions Architect with a passion for SharePoint and PowerShell

SharePoint 2020

The Vision for a Future of Clarity

Aharoni in Unicode, ya mama

Treacle tarts for great justice

Follow

Get every new post delivered to your Inbox.

Join 186 other followers

%d bloggers like this: