Search all closed web parts
28/01/2012 22:07
function Search-SPClosedWebParts
{
<#
.Synopsis
Finds instances of closed web parts on SharePoint site and sub-sites.
.Description
Finds instances of closed web parts on SharePoint site and sub-sites.
.Parameter
SiteUrl
SiteUrl to search for closed web parts
.Example
Search-SPClosedWebParts
Finds instances of closed web parts on SharePoint site and sub-sites.
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $true, valueFromPipeline=$true)]
[String]
$SiteUrl
)#end param
Begin
{
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
}
Process
{
$site = new-Object Microsoft.SharePoint.SPSite($SiteUrl)
$site.AllWebs | ForEach-Object {
$currentWeb = $_
$pages = $currentWeb.Files | Where-Object {$_.Name -match ".aspx"}
$pages | ForEach-Object {
$currentPage = $_
$webPartManager = $currentWeb.GetLimitedWebPartManager($currentPage.ServerRelativeUrl, `
[System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
$webPartManager.WebParts | ForEach-Object {
if($_.IsClosed)
{
Write-Host "'$($_.Title)' on $($currentPage.ServerRelativeUrl) is closed"
}
}
}
$currentWeb.Dispose()
}
$site.Dispose()
}
} #end Search-SPClosedWebParts
$siteUrlToSearch = Read-Host -Prompt "Enter site URL to check for closed web parts"
Search-SPClosedWebParts -SiteUrl $siteUrlToSearch