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.


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
  $myItem[[Microsoft.SharePoint.SPBuiltInFieldId]::Modified_x0020_By] = $modifiedByUserFieldValue
  $myItem[[Microsoft.SharePoint.SPBuiltInFieldId]::Editor] = $modifiedByUserFieldValue
  $myItem[[Microsoft.SharePoint.SPBuiltInFieldId]::Modified] = $oldDate
  $myItem["Modified"] = $oldDate

  $pagesList.EnableMinorVersions = $true
  $pagesList.DraftVersionVisibility = [Microsoft.SharePoint.DraftVisibilityType]::Reader

  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.

  • 2
    You should create an SPFieldUserValue object and use it instead of the actual user object! The same approach, but a different field (works the same): sharepoint.stackexchange.com/questions/84232/… Commented Dec 3, 2013 at 18:03
  • I used it same problem.
    – Medes
    Commented Dec 4, 2013 at 8:33
  • Then I think we need to see more of your code, because something is done wrong! Commented Dec 4, 2013 at 8:37
  • I have added the code. It works when I remove CheckIn and Publish method, but the page is not published.
    – Medes
    Commented Dec 4, 2013 at 9:24
  • 1
    Thank you Robert I fixed it by moving CheckIn and Publish to the begining directly after creating the publishing page.
    – Medes
    Commented Dec 4, 2013 at 9:52

2 Answers 2


Since the problem seems to be related to the Publish of the file, try this approach:

 SPFile fileDest = libDest.RootFolder.Files.Add(
     if (bolMajorVer)
/*Here we're checking if this is a major version and calling the publish method, passing in the check-in comments.  Oddly when the publish method is called the passed created and modified dates are displayed in the SharePoint UI properly without further adjustment.*/
/*Setting the created and modified dates in the SPListItem which corrects the display in the SharePoint UI version history for the draft versions.*/
          SPListItem itmNewVersion = fileDest.Item;
          itmNewVersion["Created"] = dateCreatedOn;
          itmNewVersion["Modified"] = dateModifiedOn;

Source of this code: http://sharepointvenividivici.typepad.com/sharepoint-customization/2011/06/maintain-file-version-history-when-movingcopying-files-between-sharepoint-sites.html

  • I solved the problem by moving CheckIn and Publish to the begining of the code so I checkin first then I update the Item. thanks all of you.
    – Medes
    Commented Dec 4, 2013 at 9:51

To create a SPUserField in PowerShell you can use

$user=New-Object Microsoft.SharePoint.SPFieldUserValue(web, $userId, $userName) 
$item[[Microsoft.SharePoint.SPBuiltInFieldId]::Editor] = $user
$item[[Microsoft.SharePoint.SPBuiltInFieldId]::Modified_x0020_By] = $user
  • I used it but stil modified by for all pages is same and the person executes the script. I tested Author(created by) it changed but still editor is same.
    – Medes
    Commented Dec 4, 2013 at 8:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.