SharePoint自动化系列——Content Type相关timer jobs一键执行

时间:2023-03-09 09:17:09
SharePoint自动化系列——Content Type相关timer jobs一键执行

转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/

背景:

在SharePoint Central Administration->Monitoring->Job Definitions中我们可以看到所有的timer jobs,其中和Content Type相关的timer jobs有:

  1.Content Type Hub

  2.Content Type Sucscriber(job definition的数量等于于web application的数量)

原因:

由于在web application数量较多的时候,我们在publish一个content type后要将以上所有的job都跑一遍,在UI界面上操作是非常麻烦的!而且容易重复跑或没跑到。所以需要一段脚本来自动执行所有的和content type相关的jobs,脚本内容如下:

#Start the SharePoint content type relative jobs.
Add-PSSnapin Microsoft.SharePoint.PowerShell
$ContentTypeHubJob = Get-SPTimerJob|where{$_.name -like '*MetadataHubTimerJob*'}
$ContentTypeSubscriberJobs = Get-SPTimerJob|where{$_.name -like '*MetadataSubscriberTimerJob*'}
Start-SPTimerJob $ContentTypeHubJob
foreach($job in $ContentTypeSubscriberJobs)
{
Start-SPTimerJob $job
}
$tip = "'Content Type Hub' job's LastRunTime is: " + $ContentTypeHubJob.LastRunTime
Write-Host $tip -ForegroundColor Green
for($i=0;$i -lt $ContentTypeSubscriberJobs.count;$i++)
{
$tip = "'Content Type Subscriber' job" + ($i+1) + "'s LastRunTime is: " + $ContentTypeSubscriberJobs[$i].LastRunTime
Write-Host $tip -ForegroundColor Green
}
Read-Host

将以上内容保存到ps1类型文件中,右键点击“Run with PowerShell”执行:
SharePoint自动化系列——Content Type相关timer jobs一键执行

运行结果如下:

SharePoint自动化系列——Content Type相关timer jobs一键执行