• SharePoint自动化系列——Add/Remove “Hold” from items


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

  • 相关阅读:
    内存池(MemPool)技术详解
    关于项目时间管理的六点须知
    如何与你的老大沟通?
    一个简单的面试题
    Windows下的Memcache安装与测试教程
    反向代理服务器的工作原理
    Linux下的Memcache安装方法
    TCP/IP协议详解
    浅谈负载均衡技术与分类
    MySQL数据备份和恢复的方法大全
  • 原文地址:https://www.cnblogs.com/LanTianYou/p/4973580.html
Copyright © 2020-2023  润新知