目的:批量的將SharePoint items變成records或者將records變成普通的items。web
1.Add records(用處不大,SharePoint中能夠批量添加records,還算方便):api
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是很是麻煩的事):ide
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。blog
運行效果:it
使用方法:io
一、將腳本內容中的web Url和listTitle修改爲指定的內容後保存到ps1文件,右鍵run with PowerShell便可;function
二、直接調用:class