Share via


SharePoint 2010: PowerShell Script to List Out Webparts Used in Publishing Pages

This PowerShell script will list all of the webparts used in all publishing pages in a site.

This script does not take any argument at the time of invoking it. This requires an input value for the site URL. This will be asked during the execution time and a message will be flashed to provide the name.

I have included the help text to explain the purpose of this script and it can be reached by adding -help as a argument while invoking this script. This script is tested in both SharePoint 2007 and SharePoint 2010.

param([switch]$help)                         [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")            [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Publishing")                         function GetHelp() {                         $HelpText = @" DESCRIPTION:This script will list out the webparts type along with the names in publishing pages in any site ."@            $HelpText                         }                         function RahulPublishingPageWebParts() {                 write-host "This script will enlist the webparts used in all publishing pages in this site"                write-host "Please enter theURL of the site"                $siteURL = read-host                $site = New-Object Microsoft.SharePoint.SPSite($siteURL)                $web = $site.OpenWeb()                $webPublish =  [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)                $pages = $webPublish.GetPublishingPages()                foreach($page in $pages)                {                    $manager = $web.GetLimitedWebPartManager($page.Url,[System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)                    $webCollection = $manager.WebParts                    if($webCollection.Count -ne 0)                    {                        write-host "The page "  $page.Title  " contains these webparts"                        for($i =0;$i -lt $webCollection.Count; $i++)                        {                            write-host ($i + 1).ToString()  " "  $webCollection[$i].GetType().Name  " "  $webCollection[$i].Title                        }                                 }                }             $site.Dispose()            $web.Dispose()                    }                                      if($help)             {                GetHelp; Continue             }            else             {                RahulPublishingPageWebParts            }

The sample output will be in this form:

Other Languages

This article is also available in the following languages: