Sunday 17 November 2013

Find missing webparts in a SharePoint 2010 Site Collection

Find missing webpart in a page:



stsadm -o enumallwebs -includewebparts > C:\temp\somelog.txt

Script to list all web parts in a site collection




function enumerateWebParts($Url) {
    $site = new-object Microsoft.SharePoint.SPSite $Url    foreach($web in $site.AllWebs) {
        if ([Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($web)) {
            $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
                $wps | select-object @{Expression={$pWeb.Url};Label=”Web URL”},@{Expression={$fileUrl};Label=”Page URL”}, DisplayTitle, IsVisible, @{Expression={$_.GetType().ToString()};Label=”Type”}
            }
        }
        else {
            $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
                    $wps | select-object @{Expression={$pWeb.Url};Label=”Web URL”},@{Expression={$fileUrl};Label=”Page URL”}, DisplayTitle, IsVisible, @{Expression={$_.GetType().ToString()};Label=”Type”}
                }
            }
            else {
            }
        }        Write-Host “… completed processing” $web
    }
}$row = enumerateWebParts(‘http://sp2010server:7070/’)
$row | Out-GridView



If the Integrated Script Editor (ISE) is not installed, execute the following script then go back to the script above and execute it.

Import-Module ServerManagerAdd-WindowsFeature PowerShell-ISE


No comments:

Post a Comment