Saturday, March 12, 2016

Enable-Disable Timer Jobs using PowerShell in SharePoint

Timer jobs perform specific tasks in SharePoint through Windows Timer service, such as sending email alerts at a scheduled time. In SharePoint Central Administration site you can check the timer jobs, disable or enable specific timer jobs.

PowerShell Script to Check Timer Job Status:

#Function to Check Timer job status
Function Get-TimerJobStatus($TimerJobName)
{
    $TimerJob = Get-SPTimerJob | Where-Object { $_.displayname -like $TimerJobName } 
    if($TimerJob -eq $null)
    {
        Write-host "Timer job not found!" -ForegroundColor Red
        return
    }
    $TimerJobDisabled = $TimerJob | Select -ExpandProperty IsDisabled
    if($TimerJobDisabled)
    {
        Write-host "Timer Job is Disabled!"  -ForegroundColor Yellow
    }
    else
    {
        Write-host "Timer Job is Enabled!"  -ForegroundColor Green
    }
    
}

$TimerJobName="My Site Cleanup Job"
Get-TimerJobStatus $TimerJobName

How to Disable a Timer job in SharePoint?
To disable a timer job, Head on to Central Administration >> Monitoring >> Timer Jobs >> Review job definitions >> pick your target from the list of timer jobs in SharePoint 2013 >> Click on "Disable" button to disable a Timer job.
disable sharepoint timer job powershell

Disable SharePoint timer job using PowerShell
#Function to Disable a Timer job
Function Disable-TimerJob($TimerJobName)
{
    $TimerJob = Get-SPTimerJob | Where-Object { $_.displayname -like $TimerJobName } 
    if($TimerJob -eq $null)
    {
        Write-host "Timer job not found!" -ForegroundColor Red
        return
    }
    $TimerJobDisabled = $TimerJob | Select -ExpandProperty IsDisabled
    if($TimerJobDisabled)
    {
        Write-host "Timer Job is already Disabled!" -ForegroundColor Yellow
    }
    else
    {
        $TimerJob | Disable-SPTimerJob 
        Write-host "Timer Job Disabled!" -ForegroundColor Green
    }
    
}

#Timer job name to disable
$TimerJobName="My Site Cleanup Job"

#Call the function to Disable Timer job
Disable-TimerJob $TimerJobName

Activate timer job in SharePoint:
To activate a disabled timer job, Go to:
  • Central Administration >> Monitoring >> Timer Jobs 
  • Review job definitions >> pick your target from the list of timer jobs in SharePoint 2013 
  • Click on "Enable" button to activate the timer job.
enable timer job using powershell in sharepoint
This enables the disabled timer job in SharePoint 2013.

SharePoint enable timer job with PowerShell:
#Function to Enable a Timer job
Function Enable-TimerJob($TimerJobName)
{
    $TimerJob = Get-SPTimerJob | Where-Object { $_.displayname -like $TimerJobName } 
    if($TimerJob -eq $null)
    {
        Write-host "Timer job not found!" -ForegroundColor Red
        return
    }
    $TimerJobDisabled = $TimerJob | Select -ExpandProperty IsDisabled
    if($TimerJobDisabled)
    {
        $TimerJob | Enable-SPTimerJob 
        Write-host "Timer Job Enabled!" -ForegroundColor Green
    }
    else
    {
        Write-host "Timer Job is Already Enabled!" -ForegroundColor Yellow
    }    
}

#Timer job name to Enable
$TimerJobName="My Site Cleanup Job"

#Call the function to Enable Timer job
Enable-TimerJob $TimerJobName 
This activates timer job in SharePoint 2010 with PowerShell.



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...