Thursday, 14 June 2012

How to delete a timer job using powershell in sharepoint

Recently many site admins requested me to provide an easy way to delete a timer job. A timer job can always be deleted via a non documented STSADM command as
STSADM -o deleteconfigurationobject -id guid. However this command is not recommended for production environment. Hence to resolve this issue I created a powershell script that takes only one input as the guid of the timer job and deletes it. Here is the script :



function RahulDeleteTimerJob($jobid) {

write-host "This script will delete a timer job"
        $farm = [Microsoft.SharePoint.Administration.SPFarm]::Local
        $services = $farm.Services
        foreach($service in $services)

$jobdefs = $service.JobDefinitions
foreach($job in $jobdefs)
       if($job.Id.ToString() -eq $jobid)





write-host "The job is deleted"


RahulDeleteTimerJob $jobid

I hope this will help you out.

Rahul Rashu

No comments:

Post a Comment