Run SharePoint 2010 Timer Jobs On-Demand with PowerShell
We may have to run SharePoint timer jobs on-demand in some situations. Say for e.g. To update Rating values, I had to run the timer jobs: User Profile Service Application - Social Rating Synchronization Job and User Profile Service Application - Social Data Maintenance Job. Read more at SharePoint 2010 Rating Feature Configuration
How to run timer job manually in SharePoint?
So, To run a SharePoint 2010 timer Jobs on-demand, we used to navigate to Central Administration >> Monitoring >> Timer Jobs >> Review Job Definition >> Pick the timer jobs we want to run >> Click on "Run Now", BTW SharePoint 2007 doesn't offer way to run timer job manually!
This will run timer job immediately in SharePoint 2010.
SharePoint 2013 run timer job from PowerShell:
We can run timer job from code.
I've used display name here, which various based on your installation. You can also use "Name" attribute, like:
Run SharePoint timer job programmatically with PowerShell:
In some other cases, you may have a timer job associated with multiple web applications and want to run a particular web app's timer job:
How to run timer job manually in SharePoint?
So, To run a SharePoint 2010 timer Jobs on-demand, we used to navigate to Central Administration >> Monitoring >> Timer Jobs >> Review Job Definition >> Pick the timer jobs we want to run >> Click on "Run Now", BTW SharePoint 2007 doesn't offer way to run timer job manually!
This will run timer job immediately in SharePoint 2010.
SharePoint 2013 run timer job from PowerShell:
We can run timer job from code.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue #Display name of the Timer Job to Run on-demand $TimerJobName = "User Profile SA - Social Rating Synchronization Job" #Get the Timer Job $TimerJob = Get-SPTimerJob | where { $_.DisplayName -match $TimerJobName} #start the timer job Start-SPTimerJob $TimerJob #Or use this One-liner:
#Get-SPTimerJob | where { $_.DisplayName -match "User Profile SA - Social Rating Synchronization Job"} | Start-SPTimerJob
I've used display name here, which various based on your installation. You can also use "Name" attribute, like:
$TimerJob = Get-SPTimerJob | where { $_.Name -eq "User Profile Service_SocialRatingSyncJob" }
Run SharePoint timer job programmatically with PowerShell:
In some other cases, you may have a timer job associated with multiple web applications and want to run a particular web app's timer job:
#Display name of the Timer Job to Run on-demand $TimerJobName = "Workflow Auto Cleanup" #Get the Web Application $WebApp = Get-SPWebApplication "http://sharepoint.crescent.com" #Get the Timer Job associated with the given web application $TimerJob = Get-SPTimerJob | where { $_.DisplayName -match $TimerJobName} | where {$_.Parent -eq $WebApp } #start the timer job Start-SPTimerJob $TimerJob
How to run SharePoint 2007 Timer job on-demand?
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") [void][reflection.assembly]::LoadwithPartialName("Microsoft.Office.Server") Function global:Get-SPWebApplication($WebAppURL) { return [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($WebAppURL) } #Get the web application $WebApp = Get-SPWebApplication "https://sharepoint.crescent.com" foreach ($TimerJob in $WebApp.JobDefinitions) { if($TimerJob.Title -eq "Profile Synchronization") { $TimerJob.Execute([guid]::Empty) } }Please note, This doesn't update "LastRun" time!
Using STSADM to run timer jobs on demand:
You can use "STSADM" to change the timer job schedule and make them run immediately:
E.g. Lets get "Recycle bin cleanup" timer job schedule.
stsadm -o getproperty -propertyname "job-recycle-bin-cleanup" -url "http://your-sharepoint-webpapp"
This should return the output as:
<Property Exist="Yes" Value="daily between 22:00:00 and 06:00:00" />
We can change the schedule
stsadm -o setproperty -propertyname "job-recycle-bin-cleanup" -url "http://your-sharepoint-webpapp" -propertyvalue "Every 1 minutes between 0 and 59"
Tags: sharepoint timer job execute powershell, sharepoint timer job run powershell script, run sharepoint timer job using powershell , powershell start sharepoint timer job
How do I run "User Profile Service Application - Social Data Maintenance Job" Timer Job?
ReplyDeleteTo get User Profile Service Application - Social Data Maintenance Job, use:
Delete$TimerJob = Get-SPTimerJob | where { $_.Name -eq "User Profile Service_SocialDataMaintenanceJob" }
Thanks a lot
ReplyDelete