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

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

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

相关文章
|
Go C# Windows
SharePoint自动化系列——Solution auto-redeploy using Selenium(C#)
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 本来的想法是做一个可以自动卸载并且部署新solution到SharePoint farm的tool。
1107 0
|
索引 存储
SharePoint自动化系列——Set MMS field value using PowerShell.
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 本章将总结一下设置SharePoint list中item的Managed Metadata field value的方法。
904 0
SharePoint自动化系列——Upload files to SharePoint library using PowerShell.
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 日常的SharePoint站点测试中,我们经常要做各种各样的数据,今天又写了几个脚本,发现自己写的脚本越来越多,所以我决定整理一下,并把一些常用的可复用的方法陆续发布上来。
1312 0
SharePoint自动化系列——通过PowerShell在SharePoint中批量做数据
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ PowerShell是基于.NET的一门脚本语言,对于SharePoint一些日常操作支持的很好。
1236 0
|
Web App开发
SharePoint自动化系列——通过Coded UI录制脚本自动化创建SharePoint Designer Reusable Workflow
Coded UI非常好,我开始还在想,怎么样能让一个通过SharePoint Designer创建的Workflow publish三百五十次?想不到一个好的方法,也不知道SharePoint Designer里那个publish按钮调用的是什么方法,想来想去还是用Coded UI尝试了一下,发现也挺好,在资源允许的情况下,就这样完成了SPD Workflow的自动化创建: 1.
1170 0
|
5月前
|
数据采集 运维 监控
爬虫与自动化技术深度解析:从数据采集到智能运维的完整实战指南
本文系统解析爬虫与自动化核心技术,涵盖HTTP请求、数据解析、分布式架构及反爬策略,结合Scrapy、Selenium等框架实战,助力构建高效、稳定、合规的数据采集系统。
981 62
爬虫与自动化技术深度解析:从数据采集到智能运维的完整实战指南
|
6月前
|
运维 Linux 网络安全
自动化真能省钱?聊聊运维自动化如何帮企业优化IT成本
自动化真能省钱?聊聊运维自动化如何帮企业优化IT成本
206 4
|
运维 Linux Apache
,自动化运维成为现代IT基础设施的关键部分。Puppet是一款强大的自动化运维工具
【10月更文挑战第7天】随着云计算和容器化技术的发展,自动化运维成为现代IT基础设施的关键部分。Puppet是一款强大的自动化运维工具,通过定义资源状态和关系,确保系统始终处于期望配置状态。本文介绍Puppet的基本概念、安装配置及使用示例,帮助读者快速掌握Puppet,实现高效自动化运维。
376 4

热门文章

最新文章