转载请注明出自天外归云的博客园: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.PowerShell
function 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.PowerShell
function 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

参考文献:

How to add to a hold using Powershell and Programmatically in SharePoint 2010

How to remove from a hold using PowerShell and programmatically in SharePoint 2010

SharePoint自动化系列——Add/Remove “Hold” from items的更多相关文章

  1. SharePoint自动化系列——Add/Remove "Record" from items

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 目的:批量的将SharePoint items变成records或者将records变成普通的it ...

  2. SharePoint自动化系列——Add content type to list.

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 将创建好的content type(若是跨web application需要事先publish c ...

  3. SharePoint自动化系列——Site/Web/List级别的导航菜单

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 需求:在不同的测试用例中,对脚本中不确定的因素需要和用户交互来确定,比如选择哪个site,选择哪个 ...

  4. SharePoint自动化系列——通过PowerShell创建SharePoint List Items

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 代码如下(保存到本地ps1文件中,右键run with PowerShell即可): Add-PS ...

  5. SharePoint自动化系列——Create a local user and add to SharePoint

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 实现过程:在本地创建一个local user并将该user添加到Administrators组中, ...

  6. SharePoint自动化系列——Solution auto-redeploy using Selenium(C#)

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 本来的想法是做一个可以自动卸载并且部署新solution到SharePoint farm的tool ...

  7. SharePoint自动化系列——Manage "Site Subscriptions" using PowerShell

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 你可以将普通的sites加入到你的site subscriptions中,前提是你需要有一个 Te ...

  8. SharePoint自动化系列——通过PowerShell在SharePoint中批量做数据

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ PowerShell是基于.NET的一门脚本语言,对于SharePoint一些日常操作支持的很好. ...

  9. SharePoint自动化系列——创建MMS terms

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ PowerShell脚本实现MMS group.termSet.terms的自动化创建: Add- ...

随机推荐

  1. 如何抠PSD素材中的图片

    在网上经常可以找到一些好看呢的PSD素材,如何才能将这些素材抠出来 存成一张张的png图片呢? 在PhotoShop中 1·隐藏无用的图层,然后窗口中仅剩需要看到的那个素材图 2·用工具选择该区域(注 ...

  2. !!20160829——多次错误的T+0操作

  3. CCF真题之图像旋转

    201503-1 问题描述 旋转是图像处理的基本操作,在这个问题中,你需要将一个图像逆时针旋转90度. 计算机中的图像表示可以用一个矩阵来表示,为了旋转一个图像,只需要将对应的矩阵旋转即可. 输入格式 ...

  4. JQuery书写Ajax的几种方式?

    1 $.ajax({ type: "Post", //请求方式 ("POST" 或 "GET"), 默认为 "GET" ...

  5. 在Visual Studio 2013/2015上使用C#开发Android/IOS安装包和操作步骤

    Xamarin 配置手册和离线包下载 http://pan.baidu.com/s/1eQ3qw8a 具体操作: 安装前提条件 1. 安装Visual Studio 2013,安装过程省略,我这里安装 ...

  6. 2016-9-6 批量给文件名的前面加上“igeek_高薪就业” 2、 利用FileInputStream和FileOutputStream复制文件

    在此只列出典型题目,有的题目扫一眼就有代码的不去浪费时间了,想要完整题目的评论留邮箱,看到就发.持续更新中... 1.批量给文件名的前面加上“igeek_高薪就业” package com.work; ...

  7. ASP.NET MVC (一)

    工作清闲好一段时间了,趁这段时间弄了弄PHP,做个了简单的MVC网页.玩了玩Android,弄了个拨号器,发短信的,嘿嘿,最满意的还是两天弄了个数独游戏.不务正业一个多月了,也该磨磨刀,接下来一段时间 ...

  8. 《zw版·delphi与halcon系列原创教程》zw版_THOperatorSetX控件函数列表 v11中文增强版

    <zw版·delphi与halcon系列原创教程>zw版_THOperatorSetX控件函数列表v11中文增强版 Halcon虽然庞大,光HALCONXLib_TLB.pas文件,源码就 ...

  9. DIB位图文件的格式、读取、保存和显示(转载)

    一.位图文件结构 位图文件由三部分组成:文件头 + 位图信息 + 位图像素数据 1.位图文件头:BitMapFileHeader.位图文件头主要用于识别位图文件.以下是位图文件头结构的定义: type ...

  10. Android_adb详解

    adb定义:adb(android debug bridge)是android系统中的一种命令行工具,通过它可以和android设备或模拟器通信. adb工具位置: <path-to-sdk&g ...