The Author field (created by) is not updating via the powershell script. The Editor and created and modified date fields are all updating as expected. i am pulling the list data off of a CSV. I get no errors when attempting to write to the Author field, even when I manually add junk data into the script replacing the getUser call. The getUser call is a separate function, which works fine with the Editor field,
Any ideas?
Here's a snippet of script:
foreach($row in $tblData){
item.File.Name.Length -gt 0){
if($row."FileName" -eq $item.File.Name){
write-host 'file ' $item.File.Name
$fileCount++
try{
write-host 'updating info for ' $item.File.Name
$item["Author"] = getUser($row."CreatedBy")
$item["Editor"] = getUser($row."ModifiedBy")
$item["Created"] = [DateTime]$row."CreatedAt"
$item["Modified"] = [DateTime]$row."ModifiedAt"
$item.Update()
$Context.Load($item)
$Context.ExecuteQuery()
}
catch [System.Exception]
{
Write-Host -ForegroundColor Red $_.Exception.ToString()
}
}
}
EDIT: Thanks guys. Some more information:
I am working on this as part of a migration. The script appears to set the Author field at first pass with a brand new document library. However, the Author field is then reset to me after a minute or so. I had moved the documents over with the SP Sync functionality - copying/pasting the documents locally and syncing with the new SP location, then turning off SP offline mode for the site collection. It makes a bit of sense that the fields would reset to the synced documents, but it only ever happens on the Author field - all other fields work as expected.