Restore SharePoint document timestamp and author from feedfile Restore SharePoint document timestamp and author from feedfile
Jaydeep Patel

Jaydeep Patel

January 05, 2017

All Post
Restore-SharePoint-document-timestamp-and-author-from-feedfile
Share:

Often an administrator during maintenance or checking in a document for a user, “stomps” on a timestamp and who edited the document. In a perfect world we take the time to restore authorship and timestamp. Here’s a script that reads in a CSV of the URL, timestamp and user of any number of documents to correct. it will also try to remove the previous incorrect version, if possible.

 
$actionlist= Import-Csv "C:scriptsNameDateTag.csv"
 
for ($Ai=0; $Ai -lt $actionlist.Count; $Ai++)
    {
    $ActionRow=$ActionList[$Ai]
    $docurl=$ActionRow.DocURL;
    $site = New-Object Microsoft.SharePoint Online.SPSite($docurl)
    $web = $site.OpenWeb()
    $item = $web.GetListItem($docurl)
    $list = $item.ParentList
     
    [System.DateTime] $dat = Get-Date $ActionRow.Timestamp
    $usr = $web.ensureuser($ActionRow.Editor)
     
     $item["Modified"] = $dat;
     $item["Editor"] = $usr;
        $item.Update()
     try { $item.Versions[1].delete() } catch {write-host -foregroundcolor red "Error (1) could not delete old version of $($item['Name'])"}
    }

Leave a Reply

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

Want to talk?

Drop us a line. We are here to answer your questions 24*7.