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'])"}
}
Want to talk?
Drop us a line. We are here to answer your questions 24*7.