In this article, I will provide information on how to get all the content editor webparts present under a web application using PowerShell.
Below are the components used in this document.
  1. PowerShell
  2.  SharePoint 2016

hostforlifebanner

Some time ago we get a request to collect an inventory on the current SharePoint environment; including how many content editor Webparts and the number of lists and libraries under a web application. Below is the step by step way to get all the content editor webparts present under a web application using PowerShell.

Power Shell File

Step 1
Create a text file. Name it as “GetTotalCEWP.ps1” file. Note that you will have to change the extension from “.txt” to “.ps1”
Step 2
Insert the below code to get the web application URL as an input from the user.
  1. [CmdletBinding()]
  2. param( [Parameter(Position=0,Mandatory=$true,ValueFromPipeline=$false,HelpMessage=“Input the Web Application URL.”)] [string]$WebApp)
Step 3
Insert the below code to load the SharePoint PowerShell snap in.

Step 4
Insert the below code to get all the publishing pages and then fetch the content editor webparts from those pages.

 

Step 5
There might be scenarios where we have added the content Editor webparts inside the List/Libraries forms (edit/view/display). Insert the below code to retrieve the same. We have to insert this code just before the first try/catch ends.
Step 6
Insert the below code to have the function named “GetCEWPFunction “ which would actually count the content editor webpart.
Step 7
The full file will look as attached with this article.
Step 8
Save your PowerShell File and test it by running below command. It will list down all the content editor webparts present under a web application
.\GetTotalCEWP.ps1 -WebApp http://portal.intranet.com
That is it. I hope you have learned something new from this article and will utilize this in your work.