I have an issue with a PowerShell script written for SharePoint 2010, it is only working on one site collection http://company/
, it lists all the pages using a Content Editor Web Part with Image Maps, once the loop goes to the next site collection it returns nothing.
As the script loops through all the other site collections, it returns nothing to $publishingPages
- I can see $publishingWeb
loading correctly and returning its data but I get nothing from:
$publishingWeb.GetPublishingPages($publishingWeb)
I've ran the script using different SharePoint accounts (Setup, Farm, Admin, etc), the results are always the same, I have no clue what I could be possibly doing wrong here!
Here's my code:
Start-SPAssignment -Global
$SPWebApp = Get-SPWebApplication "http://company/"
foreach ($site in $sites)
{
foreach ($web in $site.AllWebs)
{
Write-Host `n "-" $web.Url `n -ForegroundColor Green
if ([Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($web))
{
$publishingWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
$publishingPages = $publishingWeb.GetPublishingPages($publishingWeb)
foreach($page in $publishingPages)
{
$manager = $web.GetLimitedWebPartManager($page.Url, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
$allWebParts = $manager.WebParts
$onlyCEWP = $allWebParts | ? {$_.GetType() -eq [Microsoft.SharePoint.WebPartPages.ContentEditorWebPart]}
$imageMaps = $onlyCEWP | ? {$_.Content.InnerText -match '<map name='}
if ($imageMaps -ne $null)
{
Write-Host `t " - " $page.Url
}
}
}
$web.Dispose()
}
$site.Dispose()
}
Stop-SPAssignment -Global