ค้นหาเว็บไซต์

อัปเดตฟิลด์ข้อมูลเมตา "สร้างโดย", "แก้ไขล่าสุด" ของรายการโดยใช้ PowerShell


เคยต้องการอัปเดตเขตข้อมูลเมตาของรายการ SharePoint หรือไลบรารีเช่น: “สร้างโดย” “แก้ไขโดย” “สร้าง” “แก้ไขล่าสุด” หรือไม่? ค่าคอลัมน์เหล่านี้ต้องได้รับการอัปเดตขณะคัดลอกรายการจากรายการหนึ่งไปยังอีกรายการหนึ่งโดยทางโปรแกรม

ปัจจุบัน มีข้อกำหนดอื่นในการอัปเดตฟิลด์ข้อมูลเมตาในเอกสารที่จัดเก็บไว้ในไลบรารีเอกสาร SharePoint มาอัปเดตฟิลด์ข้อมูลเมตาเหล่านี้เช่น "สร้างโดย" "แก้ไขโดย" "สร้าง" "แก้ไขล่าสุด" โดยใช้ PowerShell

การอัปเดตที่สร้างโดยฟิลด์โดยใช้ PowerShell ใน SharePoint:

สคริปต์ด้านล่างเปลี่ยน "สร้างโดย" ในรายการ 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()

สคริปต์ PowerShell เพื่ออัปเดตฟิลด์ข้อมูลเมตาใน SharePoint:

ต่อไปนี้เป็นวิธีอัปเดตค่าฟิลด์สร้างโดย, แก้ไขโดย, สร้างและแก้ไขของไฟล์ใน SharePoint ด้วย PowerShell


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

บทความที่เกี่ยวข้อง