kwizcom banner advertisement

Update "Created By", "Last Modified" Metadata Fields of a List Item using PowerShell

Ever wanted to update SharePoint list or library item's metadata fields such as: "Created By" "Modified By" "Created" "Last Modified"? These column values must be updated while copying items from one list to another, programmatically.

Today, Had an another requirement to update metadata fields in a document stored in SharePoint document library. Lets update these metadata fields such as "Created By" "Modified By" "Created" "Last Modified" using PowerShell.
sharepoint change created by and modified by powershell

Update created by field using PowerShell in SharePoint:
The below script changes created by in SharePoint list item.
Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue
 
#Set Configuration Parameters
$WebURL = "http://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 Script to Update Metadata Fields in SharePoint:
Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

#Define the Parameters
$WebURL = "http://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
#Set Last Modified Date 
$Document["Modified"] = $DateValue

$Document.UpdateOverwriteVersion() #Can use $Document.SystemUpdate() as well..
Update "Created By", "Last Modified" Metadata Fields of a List Item using PowerShell Update "Created By", "Last Modified" Metadata Fields of a List Item using PowerShell Reviewed by Salaudeen Rajack on March 02, 2014 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.