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

本文提供两种PowerShell脚本:一种用于批量将SharePoint列表项声明为记录;另一种用于批量取消记录状态。这两种脚本均可处理大量列表项,提高工作效率。

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

目的:批量的将SharePoint items变成records或者将records变成普通的items。

1.Add records(用处不大,SharePoint中可以批量添加records,还算方便):

 Add-PSSnapin Microsoft.SharePoint.PowerShell
function AddRecords($webURL,$listTitle)
{
    $web = Get-SPWeb $webURL 
    $list = $web.Lists[$listTitle]
    $items = $list.Items
    Write-Host "Start declaring..." -ForegroundColor Cyan
    foreach($item in $items)
    {
        $IsRecord = [Microsoft.Office.RecordsManagement.RecordsRepository.Records]::IsRecord($Item)
        if ($IsRecord -eq $false)
        {
            Write-Host "Item declared" -ForegroundColor Green
            [Microsoft.Office.RecordsManagement.RecordsRepository.Records]::DeclareItemAsRecord($Item)
        }

    }
}
AddRecords webUrl listTitle

2.Remove records(这个用处比较大,尤其items较多时,在SharePoint中移除records是非常麻烦的事):

Add-PSSnapin Microsoft.SharePoint.PowerShell
function RemoveRecords($webURL,$listTitle)
{
    $web = Get-SPWeb $webURL 
    $list = $web.Lists[$listTitle]
    $items = $list.Items
    Write-Host "Start undeclaring..." -ForegroundColor Cyan
    foreach($item in $items)
    {
        $IsRecord = [Microsoft.Office.RecordsManagement.RecordsRepository.Records]::IsRecord($Item)
        if ($IsRecord -eq $true)
        {
            Write-Host "Item undeclared" -ForegroundColor Green
            [Microsoft.Office.RecordsManagement.RecordsRepository.Records]::UndeclareItemAsRecord($Item)
        }

    }
}
RemoveRecords webUrl listTitle  

效果:将在指定的web的指定list中批量添加/移除records。

运行效果:

使用方法:

1、将脚本内容中的web Url和listTitle修改成指定的内容后保存到ps1文件,右键run with PowerShell即可;

2、直接调用:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值