Home > PowerShell, SharePoint 2010 > Find All WebParts Being Utilized (Open/Closed) on Sites in SharePoint 2010 using PowerShell

Find All WebParts Being Utilized (Open/Closed) on Sites in SharePoint 2010 using PowerShell

I recently had a tasking where I needed to provide a listing of all webparts of a 3rd party solution (KWizCom Remote List Viewer) that were being utilized in my SharePoint 2010 Environment whether they were opened or closed on each Site Collection/Site in my Web Application.

Thanks to Ghazwan he already created a very nice script that does this for us already- http://sharepointquester.com/2012/09/11/list-all-web-parts-in-a-sharepoint-2010-site-collection-using-windows-powershell/

However I needed to do a few extra things, so I basically borrowed from this script and modify it to met my demands.

Below is the final script I used to iterate through my Web Application, check for a specific webpart type (KWizCom Remote List Viewer) and output to a .csv file.

==============================================================


function enumerateWebParts($Url)
{
$webApp = Get-SPWebApplication $Url  #Get WebApplication URL

foreach($web in $webApp | Get-SPSite -Limit All | Get-SPWeb -Limit All) #foreach loop to iterate through all sites and webs of WebApplication
{
if ([Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($web)) #Check if site is a publishing site
{
$pWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
$pages = $pWeb.PagesList
foreach ($item in $pages.Items)
{
$fileUrl = $webUrl + “/” + $item.File.Url
$manager = $item.file.GetLimitedWebPartManager([System.Web.UI.WebControls.Webparts.PersonalizationScope]::Shared);
$wps = $manager.webparts
foreach ($type in $wps) #loop through each type found $wps
{
if ($type -like "*KWizCom*") #if webpart $type -like KWizCom select webpart object
{
$wps | select-object @{Expression={$pWeb.Url};Label=”Web URL”},@{Expression={$fileUrl};Label=”Page URL”},DisplayTitle, IsVisible, @{Expression={$type};Label=”Type”}
}
}
}
}
else #if web is not a publishing site
{
$pages = $null
$pages = $web.Lists["Site Pages"]
if ($pages)
{
foreach ($item in $pages.Items)
{
$fileUrl = $webUrl + “/” + $item.File.Url
$manager = $item.file.GetLimitedWebPartManager([System.Web.UI.WebControls.Webparts.PersonalizationScope]::Shared);
$wps = $manager.webparts
foreach ($type in $wps)
{
if ($type -like "*KWizCom*")
{
$wps | select-object @{Expression={$Web.Url};Label=”Web URL”},@{Expression={$fileUrl};Label=”Page URL”},DisplayTitle, IsVisible, @{Expression={$type};Label=”Type”}
}
}
}
}
else
{
}
}
Write-Host “… completed processing” $web
}
}
$row = enumerateWebParts(‘http://WebApplication’) #call the enumerateWebParts function pass it the URL for the web application
$row | export-csv KWizCom_WebParts.csv #export csv

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: