ve often been asked to get almost any kind of report about SharePoint’s content. This time the customer asked me to get the list of all publishing pages and their page layout in a site collection. This is quite an easy task, of course using PowerShell! It’s just a matter of looping through all SPWebs in the site collections, get the page library content and print some item properties in a text file. Let’s see how to do that.
Since this is just a quick tip take a look to the comments in the script, they should be self explaining :)
if ((gsnp Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue) -eq $null){
asnp Microsoft.SharePoint.Powershell -ErrorAction Stop
}
$site = Get-SPSite http://intranet
$log = "C:\temp\PageLayouts.csv"
## Check if log file exists and clear its content
if ((Test-Path -Path $log -ea SilentlyContinue) -ne $null){
clc $log
ac $log "Page URL, Page Title, Page Layout URL, Page Layout Title"
}
## loop through all webs in the site collection
$site | Get-SPWeb -Limit All | %{
$web = $_
## Get the page library and items
$pl = $web.Lists["Pages"]
$pages = $pl.Items
foreach ($page in $pages){
## add content to the log file
ac $log "$($web.url)/$($page.Url), $($page.Title), $($page.Properties["PublishingPageLayout"])"
}
}
$site.Dispose()
asnp Microsoft.SharePoint.Powershell -ErrorAction Stop
}
$site = Get-SPSite http://intranet
$log = "C:\temp\PageLayouts.csv"
## Check if log file exists and clear its content
if ((Test-Path -Path $log -ea SilentlyContinue) -ne $null){
clc $log
ac $log "Page URL, Page Title, Page Layout URL, Page Layout Title"
}
## loop through all webs in the site collection
$site | Get-SPWeb -Limit All | %{
$web = $_
## Get the page library and items
$pl = $web.Lists["Pages"]
$pages = $pl.Items
foreach ($page in $pages){
## add content to the log file
ac $log "$($web.url)/$($page.Url), $($page.Title), $($page.Properties["PublishingPageLayout"])"
}
}
$site.Dispose()