当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 使用 PowerShell 将 SharePoint 列表列值从一个复制到另一个

作者:精品下载站 日期:2024-12-14 13:42:47 浏览:15 分类:玩电脑

使用 PowerShell 将 SharePoint 列表列值从一个复制到另一个


要求:在 SharePoint 中将列值从一个复制到另一个

如何将列值复制到 SharePoint 中的另一列?

在某些情况下,我们可能必须将 SharePoint 列表列值从一列复制到另一列。比如说,例如

  • OOTB 列不提供在多行文本字段中输入超过 255 个字符的方法。由于用户已在其中输入值并希望使其允许超过 255 个字符。
  • 当需要更改 SharePoint 字段的内部名称时。
  • 需要添加新列,其值部分基于现有列

虽然数据表视图是一种解决方案,但它并不适用于所有列表。即使在数据表视图中,某些列(例如人员选择器值)也无法复制/粘贴。所以,解决方案是:PowerShell

[玩转系统] 使用 PowerShell 将 SharePoint 列表列值从一个复制到另一个

PowerShell 在 SharePoint 中将列值从一个复制到另一个

以下是将 SharePoint 列表/库字段数据从一列复制到另一列的 PowerShell 脚本:


Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

#Parameters
$SiteURL = "https://sharepoint.crescent.com/"
$listName = "Pictures"

$web = Get-SPweb $SiteURL
 
#Use the Display Names
$CopyFromColumnName = "Description" #column copy source
$CopyToColumnName = "Desc"  #destination column

#Get the List
$list = $web.lists[$ListName]

#Get all Items  
$Items = $list.Items

ForEach ($Item in $items)
{
   #copy data from one column to another
   $item[$copyToColumnName] = $item[$copyFromColumnName]

   #Do a system update to avoid Version and to Keep same metadata
   $item.SystemUpdate($false)
}

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯