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.
- PowerShell
- SharePoint 2016
Introduction
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.
- [CmdletBinding()]
- 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.
- if ((Get - PSSnapin - Name Microsoft.SharePoint.PowerShell - ErrorAction SilentlyContinue) - eq $null) {
- Write - Host "Loading SharePoint PowerShell"
- Add - PSSnapin Microsoft.SharePoint.PowerShell
- }
Step 4
Insert the below code to get all the publishing pages and then fetch the content editor webparts from those pages.
- $SPWebApp = Get - SPWebApplication $WebApp - EA SilentlyContinue
- if ($SPWebApp - eq $null) {
- Write - Error "$WebApp url is not a valid!"
- } else {
- $allsites = $SPWebApp.Sites
- foreach($site in $allsites) {
- try {
- $allwebs = $site.AllWebs
- foreach($web in $allwebs) {
- try {
- if ([Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($web)) {
- $pubpages = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
- $allpages = $pubpages.GetPublishingPages()
- foreach($page in $allpages) {
- GetCEWPFunction - url $page.Url
- }
- }
- } catch {} finally {
- $web.Dispose()
- }
- }
- } catch {} finally {
- $site.Dispose()
- }
- }
- }

Join the conversation! Your thoughts help the community grow.