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

Ever wanted to update the 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 another requirement to update metadata fields in a document stored in the SharePoint document library. Let’s 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 a SharePoint list item.

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 Script to Update Metadata Fields in SharePoint:

Here is how to update the Created By, Modified By, Created and Modified field values of a file in SharePoint with 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..

To update Created By, Created, Modified By, Modified field values in SharePoint Online, Refer: SharePoint Online: Update Created By / Modified By, Created / Modified Field Values using PowerShell

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. Passionate about sharing the deep technical knowledge and experience to help others, through the real-world articles!

6 thoughts on “Update “Created By”, “Last Modified” Metadata Fields of a List Item using PowerShell

  • Hello, I was using this script for more than a year now – but since yesterday it stopped working:
    “$Item= $List.GetItembyID($ItemID)” stopped working…
    Error:
    You cannot call a method on a null-valued expression.
    At C:\Users\kerale\Desktop\Change_Creator.ps1:12 char:1
    + $Item= $List.GetItembyID($ItemID)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    Any ideas why this stopped working suddenly ?
    Best regards
    NK

    Reply
  • Hi How to update the created date = modified date for all the documents in a library

    Reply
  • Hi Salaudeen, how can i update only those items which are created by particular
    users only ??

    Reply
  • can i update the created by field for particular items
    i need to update all items created by domain1user_name to be domain2user_name
    my issue is that i moved all users in domain1 to domain2 with the same names but share point see them as a new different users
    i have only one list and all users have permission to access it and using a filter view to make every one see his data only ” created_by = [ME] ”
    so script moving permissions did not solve my problem to let every one see his old items created by his old user_name
    thanks and sorry for long text

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *