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”执行:

运行结果如下:

转载于:https://www.cnblogs.com/LanTianYou/p/5032769.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值