SharePoint 2016, Sharepoint 2013, Sharepoint 2010, Windows Server 2012, Sql Server 2012,2014,IIS, Active Directory,User Profile Service, Managed MetaData Service, Search Service, Topology, Web Application, IIS, Site collection, List, Library, PowerShell, office web app, Windows Authentication, NTLM, Kerberos, Saml, ADFS, Active Directory Import, MIM, SharePoint 2016 Managing Timer Jobs( Real World Example) – SharePoint

SharePoint 2016 Managing Timer Jobs( Real World Example)

Introduction

This article is a sequence of real world examples of the using PowerShell in SharePoint 2016. In this article, we will discuss how we will use the PowerShell cmdlets to managing the timer jobs in SharePoint. We will try to cover all the available cmdlets i.e get, set, enable, disable and start.

Scenario

Krossfarm having some serious issues with deleted sites and quota request, they want to stop the job from a further run  before they took care the situation. Here are the details

They want to immediately disable the timer jobs, then change the schedule of both jobs. Meanwhile, they will do their fixing stuff. Now they want to enable the timer job and immediately run both jobs so that all the backlog cleared and processed.

Steps

I split both timer jobs into two examples, but steps for both will be same with slightly different options.

  • Get the id of timer job
  • Disable the timer and check the status
  • Change the schedule of the timer job
  • Enable the timer job
  • Run the job immediately.

Example # 1

In the 1st example, we will use the “Request more quota”  timer jobs and perform all the steps.

Get ID

MR admin runs the Get-sptimerjob command but its returns all the timer jobs and very hard to identify the required timer jobs.

Get-SPTimerJob

output will be like this:
1

Now try with different options and run the below command. In this, we will apply a where filter on the DisplayName property of TimerJobs and save the output in $job variable. In 2nd line, we use the $job variable and pipe it with select to show only required properties.and yes we want to format it as a table to show everything.

$job = Get-SPTimerJob | Where-Object {$_.displayname –like “Request more quota”}  
$job | select name, DisplayName, ID, schedule | Format-Table

This will return the timer job information for related to Request More Quota. Important Thing, if you have multiples web application in your farm then use the -webapplication switch to get the timer job for specified web app.
2

Disable

Now we have the Job id and we will disable it using the below command. We will use the Disable-SptimerJob command to disable it.

Get-SPTimerJob $job | Disable-SPTimerJob
$job | Select  DisplayName, IsDisabled

This will disable the Request More Quota and output the shows if it isdisabled true or false.like this:5

Or we can do the same thing with below PowerShell.

Disable-SPTimerJob “job-quota-requestmore”
$job | Select  DisplayName, IsDisabled

Set the Schedule

After admins did their fix on the backend, Now we want to change the schedule of this timer job. For this we will use the Set-SpTimerJob command, We have to pass the -Schedule Parameter in the supported format.

Get-SPTimerJob $job | Set-SPTimerJob -Schedule "Daily at 9:00"
$job | select name, DisplayName, ID, schedule | Format-Table

This code will set the schedule of the of the timer job daily at 9 and show us the output like this:4

Or we can do same with slightly different way but output will be same.

Set-SPTimerJob “job-quota-requestmore” -Schedule "Daily at 9:00"
$job | select name, DisplayName, ID, schedule, lastruntime | Format-Table

 

Enabling

Now we want to enable the timer job(job-quota-requestmore)

Get-SPTimerJob $job | Enable-SPTimerJob
$job | Select  DisplayName, IsDisabled
This code will Enabled the disabled timer job( job-quota-requestmore).  Output will be likely this:3

Or We can use the below code to enable the same timer job. we simply give the name of the timer job.

Enable-SPTimerJob “job-quota-requestmore”
$job | Select  DisplayName, IsDisabled

Start Timer Job

Now, Last step of the example, We have to start the job.

Get-SPTimerJob $job | Start-SPTimerJob
$job | select name, DisplayName, ID, schedule, lastruntime | Format-Table

This code will start the job immediately, and the 2nd line will show us the last run time. Like this:
6

Or we can do the same thing in different way.

Start-SPTimerJob  “job-quota-requestmore”
$job | select name, DisplayName, ID, schedule, lastruntime | Format-Table

 

Example # 2

In the 2nd example, we will use the “Gradual Site Deletion”  timer jobs and perform all the steps.

Get ID

MR admin will run the below command. In this we will apply a where filter on the DisplayName property of TimerJobs and save the output in $job variable. In 2nd line we use the $job variable and pipe it with select to show only required properties.and yes we want to format it as table to show everything.

$job = Get-SPTimerJob | Where-Object {$_.displayname –like “Gradual Site Deletion”}  
$job | select name, DisplayName, ID, schedule | Format-Table

This will return the timer job information for related to Gradual Site Deletion. Important Thing, if you have multiples web application in your farm then use the -webapplication switch to get the timer job for specified web app.
2-1

Disable

Now we have the Job id and we will disable it using the below command. We will use the Disable-SPTimerJob command to disable it.

Get-SPTimerJob $job | Disable-SPTimerJob
$job | Select  DisplayName, IsDisabled

this will disable the Request More Quota and output the shows if it isdisabled true or false.like this:2-2

Or we can do the same thing with below PowerShell.

Disable-SPTimerJob “job-site-deletion”
$job | Select  DisplayName, IsDisabled

 

Set the Schedule

After admins did their fix on the backend, Now we want to change the schedule of this timer job. For this we will use the Set-SpTimerJob command, We have to pass the -Schedule Parameter in the supported format.

Get-SPTimerJob $job | Set-SPTimerJob -Schedule "Daily at 9:00"
$job | select name, DisplayName, ID, schedule | Format-Table

This code will set the schduel of the of the timer job Monthly at 1 15:00:00 and show us the output like this:2-3

Or we can do same with slightly different way but output will be same.

Set-SPTimerJob “job-site-deletion” -Schedule "Daily at 9:00"
$job | select name, DisplayName, ID, schedule, lastruntime | Format-Table

 

Enabling

Now we want to enable the timer job

Get-SPTimerJob $job | Enable-SPTimerJob
$job | Select  DisplayName, IsDisabled

This code will Enabled the disabled timer job( job-site-deletion).  Output will be likely this:
2-4
Or We can use the below code to enable the same timer job. we simply give the name of the timer job.

Enable-SPTimerJob “job-site-deletion”
$job | Select  DisplayName, IsDisabled

 

Start Timer Job

Now, Last step of the example, We have to start the job.

Get-SPTimerJob $job | Start-SPTimerJob
$job | select name, DisplayName, ID, schedule, lastruntime | Format-Table

This code will start the job immediately, and the 2nd line will show us the last run time. Like this:2-5

Or we can do the same thing in different way.

Start-SPTimerJob  “job-site-deletion”
$job | select name, DisplayName, ID, schedule, lastruntime | Format-Table

 

Hope You enjoyed and learned how to use the Manging Timer Job cmdlets.

 

 

 

 

 

 

 

 

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *