3

Good Day,

I have a list in SharePoint 2013 that I'm importing items from a csv. I need to change the created date to the created date of the imported item. I'm able to import the list item successfully but I cannot change the created date with PowerShell. I have tried on another list and it works correctly. Has anyone experienced this behavior before or know what the cause is?

Here's my code to update field

$web = Get-SPWeb "<Web Url>"
$web.AllowUnsafeUpdates = $true

$List = $web.GetList("<List Url>")

$item = $List.GetItemById(11)

$dateToStore = Get-Date "6/20/2015 11:27 AM"

$item["Created"] = $dateToStore

$item.Update()

$web.AllowUnsafeUpdates = $true
$web.Dispose()

Note, I have tried all different date formats and Update methods. There aren't any errors when running this script. The Created date is just not updated on the list item.

3

This is quite an old post but let me say something here. Created and Modified dates are readonly fields. To my understanding, to be able to modify them you need to first set their readonly property to false.

Secondly I have tested your script and with some changes following seems to be working in my case.

$web= Get-SPWeb -Identity "WebURL"
$web.AllowUnsafeUpdates = $true
$ls = $Web.Lists["ListName"]
$item = $ls.GetItemById(11)
$dateToStore = Get-Date "21/01/2017"
$item["Created"] = $dateToStore
$item.UpdateOverwriteVersion()
$web.AllowUnsafeUpdates = $true
$web.Dispose()

Cheers Vaqar

  • 1
    Just as an FYI, you can also edit the Created and Modified dates directly in the SQL databases but that's even more of a no-no and should only be done as a last resort if you absolutely MUST change the dates. – Arin Zandbergen Apr 11 '17 at 17:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.