O365 and SharePoint: List of WebParts in all sites of Web Application by using PowerShell

As we aware the WebpartManager class is helpful in Server side object model. The question popped-up in my mind “Is this possible by using PowerShell scripting?“.

I found answer as “Yes”.

Below is the code snippet to achieve the same,

$oContentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService;
[Microsoft.SharePoint.Administration.SPWebApplicationCollection]$waCollection = $oContentService.WebApplications;
$log = “.\results.txt” # output file name and path
$pagepath = “/default.aspx” # you can change page name or page path
“Site URL; WebPart Title ; Webpart ID” | out-file $log
$waCollection1 = $waCollection | where-object {$_.IsAdministrationWebApplication -eq $FALSE}
foreach ($wa in $waCollection1)
{
foreach ($obj in $wa.Sites)
{
write-host “Processing site: ” , $siteURL
$siteURL = $obj.URL

$site=new-object Microsoft.SharePoint.SPSite($siteURL)

$pageURL = $siteURL + $pagepath
$web=$site.Openweb()
$webpartmanager=$web.GetLimitedWebPartManager($pageURL, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
foreach ($webpart in $webpartmanager.WebParts)
{
$siteURL + “; ” + $webpart.Title + ” ; ” + $webpart.ID | out-file $log -append
}
}

Advertisements

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