0

It is possible to delete a time job using Powershell and the following command:

Get-SPTimerJob | where { $_.name -like "*JobName*" } |ft id,name
$job = Get-SPTimerJob -id {JobID}
$job.Delete()

Is it also possible to do this for all TimerJob which are returned by Get-SPTimerJob?

EDIT: I am looking for an answer and a working code snippet which will do as I described above.

5
  • I would assume that is very easy to test. Commented Sep 13, 2016 at 9:56
  • okay and on which basis are you assuming? references? Commented Sep 13, 2016 at 9:59
  • 1
    I am assuming based on experience. You probably tested your original query? If you did, test the one where you remove multiple timer jobs. Commented Sep 13, 2016 at 10:06
  • ehm, I am looking for an answer for my question and optionally for a correct command (have updated the question)... Commented Sep 13, 2016 at 10:15
  • 1
    Kindly check here...sharepoint.stackexchange.com/questions/22368/… Commented Sep 13, 2016 at 10:15

3 Answers 3

1

here is the PowerShell script that takes only one input as the guid of the timer job and deletes it.

Here is the script :

param([string]$jobid)

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")


function oDeleteTimerJob($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)
{

          $job.Delete()

}

}

}

write-host "The job is deleted"

}

oDeleteTimerJob $jobid

I got reference from below MSDN link

How to delete a timer job using powershell in sharepoint

1
  • pfuu, thanks dude but I think I will use my option due to less code and more redability. Commented Sep 13, 2016 at 10:22
0

okay, thanks to @Hardik's comment I ended up with the following:

$jobToDelete = Get-SPTimerJob | where { $_.name -like "*jobName*" }
$jobToDelete.Delete()

That was easy :D

3
  • Nice to see working code for you in answer. My Pleasure. :) Commented Sep 13, 2016 at 10:21
  • @Hardik I would have also gave you the answer points ;) Commented Sep 13, 2016 at 10:24
  • Thanks dude, You can choose any of the method as my given answer contains the precise code to do so. Anyway you are your own BOSS..:) Commented Sep 13, 2016 at 10:26
0
Get-SPTimerJob -WebApplication "http://devsite" | ForEach-Object{ 
   Write-Host $_.id "|" $_.name
   $_.Delete()
}

This is another way to do it.

Note: This gives all timer jobs associated with your webapplication specified

Edit:

Get-SPTimerJob | where { $_.name -like "*jobName*" }| ForEach-Object{ 
    Write-Host $_.id "|" $_.name
    $_.Delete()
}

This will delete jobs having the name mentioned in 1st statement that is jobName

3
  • but one has to know what he is doing to run this code! otherwise... Commented Sep 13, 2016 at 10:23
  • Both options iterates through each timer job returned by Get-SPTimerJob as you were requesting. Which finally I am deleting Commented Sep 13, 2016 at 10:26
  • I have added a line before deleting, which shows Id and name of timer job Commented Sep 13, 2016 at 10:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.