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

[玩转系统] 使用 PowerShell 更新列表项的“创建者”、“上次修改”元数据字段

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

使用 PowerShell 更新列表项的“创建者”、“上次修改”元数据字段


是否曾经想要更新 SharePoint 列表或库项目的元数据字段,例如:“创建者”“修改者”“创建者”“上次修改者”?当以编程方式将项目从一个列表复制到另一个列表时,必须更新这些列值。

今天,还有另一个要求更新存储在 SharePoint 文档库中的文档中的元数据字段。让我们使用 PowerShell 更新这些元数据字段,例如“创建者”、“修改者”、“创建者”、“上次修改者”。

[玩转系统] 使用 PowerShell 更新列表项的“创建者”、“上次修改”元数据字段

在 SharePoint 中使用 PowerShell 由字段创建的更新:

以下脚本更改 SharePoint 列表项 中的“创建者”。


Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue
 
#Set Configuration Parameters
$WebURL = "https://portal.crescent.com/IQ/"
$ListName = "Questionnaire"
$ItemID = "147"
$UserName = "Crescent\Hamid"
 
#Get the Web, List, Item and User objects
$Web= Get-SPWeb $WebURL
$List= $web.Lists[$ListName]
$Item = $List.GetItembyID($ItemID)
$Author =$web.EnsureUser($UserName)
 
#update the created by & modified by columns
$Item["Author"] = $Author
$Item["Editor"] = $Author
$Item.SystemUpdate()

用于更新 SharePoint 中元数据字段的 PowerShell 脚本:

以下介绍了如何使用 PowerShell 更新 SharePoint 中文件的创建者、修改者、创建者和修改者字段值。


Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

#Define the Parameters
$WebURL = "https://sharepoint.crescent.com/projects/1033/"
$LibraryName = "Project Documents"
$DocumentName = "Project Schedules.xlsx"
$UserName = "Global\EricCo"
$DateValue = "2013-01-01 10:05" # Should be in "yyyy-mm-dd HH:mm" format

#Get the Web 
$web= Get-SPWeb $WebURL
#Get the Library
$list= $web.Lists[$LibraryName]
#Get the User
$Author =$web.EnsureUser($UserName)
#Get the document
$Document = $list.Items | where {$_.Name -eq $DocumentName}

#update created by column sharepoint programmatically
$Document["Author"] = $Author
#set modified by programmatically
$Document["Editor"] = $Author

#Set Created Date value
$Document["Created"] =  $DateValue

#sharepoint powershell to update modified date
$Document["Modified"] = $DateValue

$Document.UpdateOverwriteVersion() #Can use $Document.SystemUpdate() as well..

要更新 SharePoint Online 中的创建者、创建者、修改者、修改者字段值,请参阅:SharePoint Online:使用 PowerShell 更新创建者/修改者、创建/修改者字段值

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

取消回复欢迎 发表评论:

关灯