I have an enterprise wiki site collection inside my sharepoint on-premises farm 2013. now i have imported some wiki pages from different farm. and since the users who created the original wiki pages do not exists inside our farm, so the createdby and the modifiedby fields for the wiki pages have been set to "System Account" after doing the import operation for the Pages list. now i want to modify the CreatedBy & ModifiedBy fields for all my enterprise wiki pages , so i tried this power-shell script where i used similar appraoch mentioned in this link:-
#specify new user - login name
$newuser = $web.EnsureUser("ad-***\****.***")
#specify the web URL
$site = get-SPWeb http://****/kb/WikiSite/
#specify the list name
$list = $site.Lists["Pages"]
$listitems = $list.Items
$user = get-SPuser -Web $site -Identity $newuser
#loop through each list item and update
$Site.AllowUnsafeUpdates = $true
foreach ($listitem in $listitems)
{
$listitem["Author"] = $user
$listitem["Editor"] = $user
$listitem.Update()
write-host $listitem["Name"] "has been updated. The author and editor has been set to $user"
}
$site.Update()
$site.Dispose()
but i got this error:-
Exception calling "Update" with "0" argument(s): "Invalid data has been used to update the list item. The field you are trying to update may be read only." At line:5 char:9 + $listitem.Update() + ~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : SPException
now i tried to use $listitem.UpdateOverwriteVersion()
instead of $listitem.Update()
,, but did not fix the problem.. so can anyone adivce on this problem please?
$listitem.SystemUpdate()