首页 > 其他 > 详细

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

时间:2015-12-10 19:13:23      阅读:153      评论:0      收藏:0      [点我收藏+]

目的:批量的将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。

运行效果:

技术分享

使用方法:将脚本内容中的web Url和listTitle修改成指定的内容后保存到ps1文件,右键run with PowerShell即可。

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

原文:http://www.cnblogs.com/LanTianYou/p/5036549.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!