I am trying to create about 1000 publishing pages using powershell. The powershell script reads data from a xml file. I have to update Modified By field for all newly created pages. I have used
$item["Editor"] = $user
$item[[Microsoft.SharePoint.SPBuiltInFieldId]::Modified_x0020_By] = $user
and tested all following options for updating the item.
$item.Update()
$item.SystemUpdate($true)
$item.SystemUpdate($false)
$item.UpdateOverwriteVersion()
but When I go to the pages list and, all pages is updated by user who executed the powershell. Updated: added Code
$myWeb = Get-SPWeb $WebUrl
$myPublishWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($myWeb)
$pagesListName = $myPublishWeb.PagesListName
$newFile = $myweb.GetFile("$pagesListName/temp.aspx")
if (-not($PersonaltidningspolicyFile.Exists))
{
$myPage = $myPublishWeb.AddPublishingPage("temp.aspx", $myPageLayout)
$myPage.Title = "Title Value"
$myItem = $myPage.ListItem
$modifiedBy = $myWeb.EnsureUser("domain\testuser")
$modifiedByUserFieldValue = New-Object Microsoft.SharePoint.SPFieldUserValue($myWeb, $modifiedBy.ID, $modifiedBy.Name)
$pagesList = $myPublishWeb.PagesList
$myItem["Title"] = "Title Value"
$pagesList.EnableMinorVersions = $false
$pagesList.Update()
$myItem[[Microsoft.SharePoint.SPBuiltInFieldId]::Modified_x0020_By] = $modifiedByUserFieldValue
$myItem[[Microsoft.SharePoint.SPBuiltInFieldId]::Editor] = $modifiedByUserFieldValue
$myItem[[Microsoft.SharePoint.SPBuiltInFieldId]::Modified] = $oldDate
$myItem["Modified"] = $oldDate
$myItem.UpdateOverwriteVersion()
$pagesList.EnableMinorVersions = $true
$pagesList.DraftVersionVisibility = [Microsoft.SharePoint.DraftVisibilityType]::Reader
$myPublishWeb.Update()
if($newFile.CheckOutStatus -ne [Microsoft.SharePoint.SPFile+SPCheckOutStatus]::None)
{
$newFile.CheckIn("From Powershell")
$newFile.Publish("frrom Powershell")
}
}
I have used UpdateOverwriteVersion and EnableMinorVersions to make it possible change the last modified date. I have even removed it and tested creating new page without that code and using systemUpdate(false) without success.
Everything works greate if I remove last part of the code (CheckIn and Publish) but I need to publish the newly created page.