博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SharePoint自动化系列——Add/Remove “Hold” from items
阅读量:7079 次
发布时间:2019-06-28

本文共 2527 字,大约阅读时间需要 8 分钟。

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

问题1:

1.如果SharePoint item被添加了hold,通过UI界面来对SharePoint items解锁是比较折腾的。

2.而且这其中存在一个问题,我们可以看作是已知问题——对于文件的解锁,是可以通过UI界面完成的;而对于list中的items,我们通过UI界面是无法完成解锁的,因为当你在item中上传附件并对其添加hold后,你是无法通过item的Property->Advanced再进入Compliance details中的,所以无法完成对item附件的解锁。

而对于以上的两个问题——解锁过程的繁琐和无法解锁,我们可以通过一个脚本来解决:

Add-PSSnapin Microsoft.SharePoint.PowerShellfunction RemoveHolds($siteURL,$listTitle){    $site = Get-SPSite $siteURL    $web = $site.RootWeb    $list = $web.Lists[$listTitle]    $items = $list.Items    $holds = $web.Lists["Holds"].Items    $holdsCount = $holds.Count    Write-Host "Holds in this site:" -ForegroundColor DarkCyan    for($i=0;$i -lt $holdsCount;$i++)    {        $tip = "["+$i+"] "+$holds[$i].title        Write-Host $tip -ForegroundColor DarkYellow    }    $choose = Read-Host "Choose the hold you wanna remove from items"    $itemHold = $web.Lists["Holds"].items[[int]$choose]    [Microsoft.Office.RecordsManagement.Holds.Hold]::RemoveHold($items,$itemHold,"Hold removed from all the items")    $web.Dispose()    $site.Dispose()}$siteURL = "http://exhv-3073/sites/1116site1"$listTitle = "1116docLib"RemoveHolds $siteURL $listTitle

直接在PowerShell或者PowerShell ise中运行这段脚本:

如上所示,在输入siteURL和listTitle后运行程序,选择相应的hold,就可以对list中的items进行解锁了。解锁后的items就可以正常进行编辑或删除了。

问题2:

1.为items添加hold和remove hold from items一样麻烦;

2.无法批量地为items添加hold。

同样用一个脚本解决,只需要将上段代码中稍作修改即可:

Add-PSSnapin Microsoft.SharePoint.PowerShellfunction AddHolds($siteURL,$listTitle){    $site = Get-SPSite $siteURL    $web = $site.RootWeb    $list = $web.Lists[$listTitle]    $items = $list.Items    $holds = $web.Lists["Holds"].Items    $holdsCount = $holds.Count    Write-Host "Holds in this site:" -ForegroundColor DarkCyan    for($i=0;$i -lt $holdsCount;$i++)    {        $tip = "["+$i+"] "+$holds[$i].title        Write-Host $tip -ForegroundColor DarkYellow    }    $choose = Read-Host "Choose the hold you wanna add to items"    $itemHold = $web.Lists["Holds"].items[[int]$choose]    [Microsoft.Office.RecordsManagement.Holds.Hold]::SetHold($items,$itemHold,"Hold added")    $web.Dispose()    $site.Dispose()}$siteURL = "http://exhv-3073/sites/1116site1"$listTitle = "1118docLib"AddHolds $siteURL $listTitle

直接在PowerShell或者PowerShell ise中运行这段脚本:

另,一键执行所有和Hold processing and reporting的jobs:

#Run the 'Hold processing and reporting'timer jobs.$jobs = Get-SPTimerJob|where{
$_.name -like '*hold*'}foreach($job in $jobs){ Start-SPTimerJob $job}

或:

Get-SPTimerJob|where{$_.name -like '*Hold*'}|Start-SPTimerJob

参考文献:

你可能感兴趣的文章
自动化交易机器人Beta猪
查看>>
About SOuP
查看>>
常用网络设备
查看>>
【Gamma】Scrum Meeting 4
查看>>
kafa单机版环境搭建
查看>>
kettle报错收集
查看>>
减少Linux 电耗 转自IBM
查看>>
DIOCP3-DIOCP1升级到DIOCP3
查看>>
SQL Server 中WITH (NOLOCK)浅析
查看>>
09网易校园招聘笔试题
查看>>
。一个通俗易懂的HMM例子
查看>>
freeswitch 挂断前执行脚本
查看>>
EffectManager
查看>>
python packages prebuild for windows
查看>>
这样就算会了PHP么?-10
查看>>
远程调用WMI安装软件
查看>>
从零开始学习jQuery (七) jQuery动画-让页面动起来!
查看>>
asp.net 操作word
查看>>
SQL Server 权限管理
查看>>
郎意难坚,侬情自热(文/王路)
查看>>