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

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

This powershell script will enlist all 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 same.

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 MOSS 2007 and SPS 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:



Leave a Comment
  • Please add 4 and 4 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
Comments
  • Fernando Lugão Veltem edited Revision 4. Comment: remove en-us from title

  • Craig Lussier edited Revision 3. Comment: added en-US to tags and title. removed long and unneeded tags not in line with tagging protocols

  • Ed Price - MSFT edited Revision 1. Comment: TItle casing and tags

Page 1 of 1 (3 items)
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Comments
  • Ed Price - MSFT edited Revision 1. Comment: TItle casing and tags

  • Craig Lussier edited Revision 3. Comment: added en-US to tags and title. removed long and unneeded tags not in line with tagging protocols

  • Fernando Lugão Veltem edited Revision 4. Comment: remove en-us from title

Page 1 of 1 (3 items)