I edited the Content property of a Content Editor Web part via powershell but when I first view the page, it is not getting reflected. When i click edit once , I see my changes . What could the issue for the changes to the web part not getting reflected even on Page refresh ?

  Function EditProperties($SiteCollectionURL) {

    $Web = Get-SPWeb $SiteCollectionURL

    $PublishingWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)

    $PublishingPages = $PublishingWeb.GetPublishingPages()      

    foreach ($Page in $PublishingPages)

        $WebPartManager = $web.GetLimitedWebPartManager($Page.Url,[System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)

        foreach($webPart in $WebPartManager.WebParts)

            if($webPart.GetType() -eq [Microsoft.SharePoint.WebPartPages.ContentEditorWebPart])


                  $oldXmlElement = $webPart.Content;
                  $oldXmlElement.InnerText =  'Edited Content here!';  
                  $webpart.Content = $oldXmlElement


    $page.CheckIn("CEWP Updated") 
    $Page.ListItem.File.Publish("CEWP Updated")


  • Code is absolutely fine. Have you added other webpart on page? Nov 21 '16 at 7:50
  • There are other web parts on the page too. Those don't need modifications from powershell. Only this web part gets updated from a powershell script Nov 21 '16 at 8:54
  • Yes, Other webparts are creating problem. Just for check, close other webparts and run powershell command. Nov 21 '16 at 8:59
  • I tried it on an empty page and It still did not get updated until I pressed the Edit page button once Nov 21 '16 at 10:05
  • Please check in Inspect tool (F12), is there any javascript error? I used same code. i am not getting any issue like this. Nov 21 '16 at 10:20

Try the following:

$xmlDoc = New-Object System.Xml.XmlDocument
$contentXml = $xmlDoc.CreateElement("Content") 

$contentXml.InnerText = 'Edited Content here!'
$webpart.Content = $contentXml
  • I have tried this. It didnt work. Nov 21 '16 at 9:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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