question

BhaskarPadmanabhan-4392 avatar image
0 Votes"
BhaskarPadmanabhan-4392 asked BhaskarPadmanabhan-4392 commented

How to get the Content editor contents(data) using PNP powershell in sharepoint 2013

I'm trying to get the contents of Content editor webpart using PNP PowerShell in SharePoint 2013 on-premise Server.
Appreciate if anyone can provide any lead.

office-sharepoint-server-development
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

EchoDu-MSFT avatar image
0 Votes"
EchoDu-MSFT answered BhaskarPadmanabhan-4392 commented

Hello @bhaskarpadmanabhan-4392 ,

Welcome to Q&A Forum!

Based on my research and testing, we cannot get the Content Editor webpart contents(data) using PNP powershell in sharepoint 2013.

You can use the below PowerShell command to find CEWP’s with script in your SharePoint sites.

 [CmdletBinding()]
 param([Parameter(Position=0,Mandatory=$true,ValueFromPipeline=$false,HelpMessage="Specifies the URL of the Web Application.")] 
       [string]$WebApplication)
     
 function Get-CEWP([string]$url)
 {
    $manager = $web.GetLimitedWebPartManager($url, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
    $webParts = $manager.WebParts
    if ($webParts.Count -ne 0)
    {
       foreach ($webPart in $webParts)
       {
          if ($webPart.GetType() -eq [Microsoft.SharePoint.WebPartPages.ContentEditorWebPart])
          {
             if ($webPart.ContentLink.Length -gt 0)
             {
                # Check file in ContentLink for script tags
                $file = $web.GetFile($webPart.ContentLink)
                $data = $file.OpenBinary()
                $encode = New-Object System.Text.ASCIIEncoding
                $contents = $encode.GetString($data)
                if ($contents.ToLower().Contains("<script>"))
                {
                    Write-Output "$($web.Url)/$url (CONTENTLINK)"
                }
                break
             }
     
             if ($webPart.Content.InnerText.Contains("<script>"))
             {
                Write-Output "$($web.Url)/$url (HTML)"
             }
          }
       }
    }
 }
     
 # Load the SharePoint PowerShell snapin if needed
 if ((Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null)
 {
    Write-Host "Loading the SharePoint PowerShell snapin..."
    Add-PSSnapin Microsoft.SharePoint.PowerShell
 }   
        
 $SPWebApp = Get-SPWebApplication $WebApplication -EA SilentlyContinue
 if ($SPWebApp -eq $null)
 {
    Write-Error "$WebApplication is not a valid SharePoint Web application. Aborting execution!"
 }
 else
 {
    Write-Host -ForegroundColor Green "Please wait... gathering data."
    $sites = $SPWebApp.Sites
    foreach ($site in $sites)
    {
       try
       {
          $webs = $site.AllWebs
          foreach ($web in $webs)
          {
             try
             {
                # For publishingwebs, check all publishingpages
                if ([Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($web))
                {
                   $pubweb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
                   $pages = $pubweb.GetPublishingPages()
                   foreach($page in $pages)
                   {
                      Get-CEWP -url $page.Url
                   }
                }
                        
                # Libraries and lists have views and forms which can contain webparts... let's get them also
                $lists = $web.lists
                foreach ($list in $lists)
                {
                   # Check the views
                   $views = $list.Views
                   foreach ($view in $views)
                   {
                      Get-CEWP -url $view.Url
                   }
                            
                   # Check the forms
                   $forms = $list.Forms
                   foreach ($form in $forms)
                   {
                      Get-CEWP -url $form.Url
                   }
                }
             }
             catch {}
             finally { $web.Dispose() }      
          }
       }
       catch {}
       finally { $site.Dispose() }
    }
 }

108443-3.png

Reference:

http://blog.kuppens-switsers.net/sharepoint/finding-cewps-with-script-in-your-sharepoint-sites/

Thanks,
Echo Du
=============================================
If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.





3.png (28.4 KiB)
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @bhaskarpadmanabhan-4392 ,

Is there anything else I can help with regarding this issue?

You can comment us at any time and we will continue to follow up.

Thanks,
Echo Du

0 Votes 0 ·

Hi @bhaskarpadmanabhan-4392 ,

Would you tell me whether your issue has been resolved or have any update ?
I am looking forward to your reply.

Have a nice day!

Thanks,
Echo Du

0 Votes 0 ·

Hi Echo Du,

My issue is not resolved. I'm able to get text data from webpart but not picture or hyperlinks. I have pasted the code here: https://docs.microsoft.com/en-us/answers/questions/469037/fetching-webpart-contents-using-pnp-powershell.html
Can you please guide me in getting hyperlink contents

0 Votes 0 ·