Updating CEWB content using Client powershell RRS feed

  • Question

  • Hi

    I am trying to update the contents for CEWB using the client powershell but the method save changes is not available in this, what can be an alternate solution this?

    to save the changes or anything else wrong with my script?

    # Begin the process
    $loadInfo1 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
    $loadInfo2 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
    $loadInfo3 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.UserProfiles")
    #Add SharePoint PowerShell SnapIn if not already added
    $snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'} 
    if ($snapin -eq $null) 
    	Write-Host "Loading SharePoint Powershell Snapin"    
    	Add-PSSnapin "Microsoft.SharePoint.Powershell"  -EA SilentlyContinue
    # Function to add Site Content link in thes where it does not exists
    function addContentCEWB( $data,$imagePath,$CSVData)
         foreach ($row in $CSVData)  
            $pageURL = $webURL + $
            $file= $spoCtx.Web.GetFileByUrl($pageURL)
                #Web Part Manager to get all web parts from the file
                $limitedWebPartManager = $file.GetLimitedWebPartManager([Microsoft.Sharepoint.Client.WebParts.PersonalizationScope]::Shared);
                write-host $limitedWebPartManager.WebParts.AreItemsAvailable;
                write-host $limitedWebPartManager.WebParts.Count;
                #Iterate through each web part
                foreach($webPart in $limitedWebPartManager.WebParts) 
                    $propValues = $webpart.WebPart.Properties.FieldValues  
                    # Get the Content Editor web part with specific Title
                    if( ($propValues.Title -eq "addContent") )#-and ($webPart.GetType() -eq [Microsoft.SharePoint.WebPartPages.ContentEditorWebPart]) )
                        #Content to be Placed inside CEWP
                        $HtmlContent= $data
                        $XmlDoc = New-Object System.Xml.XmlDocument
                        $contentXml.InnerText= $HtmlContent
                        #Set content and Save
                        $["Content"]  = $contentXml    
                    Write-Host("Exception at Site Collection Url :" + $pageURL + $_.Exception.Message)                    
                    $logfile.WriteLine($webURL+"`t"+ $pageURL +"`t"+$_.Exception.Message)              



    Tuesday, March 20, 2018 12:28 PM

All replies

  • Hi,

    I may not directly answer your question, however if you intend to update the CEWP content - you can use different strategy. For example by using Content Link in CEWP - where you can specify external HTML file for content source.

    Best regards,

    Riwut Libinuko
    Principal Architect, Singapore
    Office Servers and Services MVP | Singapore
    Blog :

    Tuesday, March 20, 2018 1:12 PM
  • I have to do it on many pages, hence trying to automate it


    Tuesday, March 20, 2018 2:03 PM