PNP Powershell to Set the Modified (or Created) date on a List Item

Want to set the modified date or created date on a list item to some time in the past?  (You must have at least “Edit” rights on the list).  This PowerShell will do it for you, if you have the SharePoint PNP PowerShell installed (Installation instructions here: https://docs.microsoft.com/en-us/powershell/sharepoint/sharepoint-pnp/sharepoint-pnp-cmdlets?view=sharepoint-ps).

Three simple steps,

  • Set up variables
  • Connect to the web
  • Update the item

Here is the code to modify item id 90 on the list coylejunk so that the modified date is 11/11/2016 and the creation date is 1/1/2016:

$targetUrl                  = "PutTheAddressToYourWebHere"

$ModifiedDate               = "2016-11-11T10:00:00-00:00"
$CreateDate                 = "2016-01-01T08:00:00-00:00"
$targetList                 = "coylejunk"
$IdToUpdate                 = 90

Connect-PnPOnline $targetUrl
Set-PnPListItem -List $($targetList) -Identity $IdToUpdate -Values @{"Modified"=$ModifiedDate;"Created"=$CreateDate}

Bonus: Do you want to also update the CreatedBy (Author) and ModifiedBy (Editor) fields?

Get the user’s email address and augment the Set-PnpListItem statement as follows:
Set-PnPListItem -List $($targetList) -Identity $IdToUpdate -Values @{“Modified”=$ModifiedDate;”Created”=$CreateDate;”Author”=”Jsmith@SunCenter.com”;”Editor”=”JBarbarie@SunCenter.com”;}

Posted in PowerShell, SharePoint In General
2 comments on “PNP Powershell to Set the Modified (or Created) date on a List Item
  1. Avian Decosta says:

    Hello

    I am using latest version PNPONline

    I am using following command, except Author field nothing is updating. Please advise what I am missing here.

    Set-PnPListItem -List $Docs -Identity $Item -Values @{“Editor”=”22″;”Author”=”22″;”Title”=””;”Created”=$CreateDate} -SystemUpdate

    I also tried as
    Set-PnPListItem -List $Docs -Identity $Item -Values @{“Editor”=”user@domain.com”;”Author”=”user@domain.com”;”Title”=””;”Created”=$CreateDate} -SystemUpdate

    • David Jenkins says:

      You have to update after the Add-PNPListItem command.

      Example:
      $Values = @{
      “Title” = $qaDBentry[“Title”];
      ”Created”=$qaDBentry[“Created”];
      ”Author”=$creatorLookup.Email;
      }

      $newListItem = Add-PnPListItem -List “MyList” -Values $Values -Connection $destinationSite -ContentType $qaDBentryContentType.Name
      $newListItem[“Modified”] = $qaDBentry[“Modified”];
      $newListItem[“Editor”] = $editorLookup.Id;
      $newListItem.UpdateOverwriteVersion();
      $newListItem.Context.ExecuteQuery()

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: