Powershell script to list all sharepoint 2010/2007 pages and their layouts
13,821
This will do it for publishing pages:
filter Get-PublishingPages {
$pubweb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($_)
$query = new-object Microsoft.SharePoint.SPQuery
$query.ViewAttributes = "Scope='Recursive'"
$pubweb.GetPublishingPages($query)
}
get-spweb $url | Get-PublishingPages | select Uri, Title, @{Name='PageLayout';Expression={$_.Layout.ServerRelativeUrl}}
Author by
Admin
Updated on June 04, 2022Comments
-
Admin almost 2 years
I'm trying to write a powershell script which will run all over my sharepoint 2010/2007 pages and will list their page layout and will save the results into a text file.
while running the following script which i worte, i get after acouple of minuets an error:
EnumeratePages : Exception has been thrown by the target of an invocation. At T:\listpages.ps1:75 char:15 + EnumeratePages <<<< ('http://preportal.idc.ac.il') + CategoryInfo : NotSpecified: (:) [EnumeratePages], TargetInvocationException + FullyQualifiedErrorId : System.Reflection.TargetInvocationException,EnumeratePages
# Add SharePoint cmdlets reference Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue function EnumeratePages($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 Write-Host "Processing Web:" $pWeb.Url "..." -ForegroundColor Magenta foreach ($item in $pages.Items) { $fileUrl = $pWeb.Url + $webUrl + "/" + $item.File.Url Write-Host " " $fileUrl -ForegroundColor Green foreach ($fld in $item.Fields) { if($fld.Title -and $fld.InternalName -and $item[$fld.InternalName]) { if($fld.InternalName -eq "PublishingPagelayout") { Write-Host "PublishingPagelayout: " + $item[$fld.InternalName].ToString() Select "Page Url: ", $fileUrl, "PublishingPagelayout: ", $item[$fld.InternalName].ToString() | Format-List } } #$spFile = $web.GetFile($fileUrl.ToString()) #if($spFile.Properties.Count -gt 0) #{ #} } } } else { Write-Host " Not a publishing web:" $web.Url". Looking for Site Pages library." -ForegroundColor Magenta $pages = $null $pages = $web.Lists["Site Pages"] if ($pages) { Write-Host " " $pages.Title "found." -ForegroundColor Green foreach ($item in $pages.Items) { $fileUrl = $pWeb.Url + $webUrl + "/" + $item.File.Url Write-Host " " $fileUrl -ForegroundColor Green foreach ($fld in $item.Fields) { if($fld.Title -and $fld.InternalName -and $item[$fld.InternalName]) { if($fld.InternalName -eq "PublishingPagelayout") { Write-Host "PublishingPagelayout: " + $item[$fld.InternalName].ToString() Select "Page Url: ", $fileUrl, "PublishingPagelayout: ", $item[$fld.InternalName].ToString() | Format-List } } } #$spFile = $web.GetFile($fileUrl) #if($spFile.Properties.Count -gt 0) #{ #} } else { Write-Host " Site Pages library not found." -ForegroundColor Red } } Write-Host "... completed processing" $web "..." -ForegroundColor Magenta } } } $row = EnumeratePages('http://server-name') $row > t:\SitePagesPropertiesReport2.txt
Please advise.