Powershell script to list all sharepoint 2010 pages and their layouts

clear
filter Get-PublishingPages {
$pubweb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($_)
$query = new-object Microsoft.SharePoint.SPQuery

$query.ViewAttributes = “Scope=’Recursive'”
$pubweb.GetPublishingPages($query)
}

$str = Read-Host “Enter Site URL: ”
if($str -eq $null )
{
Write-Host “Enter a valid URL”
return
}

$site = Get-SPSite -Identity $str
if($site -eq $null)
{
Write-Host “Enter a valid URL”
return
}

$allweb = $site.Allwebs
foreach($web in $allweb )
{
$web | Get-PublishingPages | select Uri, Title, @{Name=’PageLayout’;Expression={$_.Layout.ServerRelativeUrl}}| Format-List
}

Advertisements

2 thoughts on “Powershell script to list all sharepoint 2010 pages and their layouts

  1. Hello,

    Could you please help me, i am looking for the same thing for all pages type ( i tried this script and i get all publishing.

    Brgds,

    Like

  2. Hello,

    I just write a script that retrieve all .aspx file in one site collection :

    $siteURL = “http://yoursite/”
    set-variable -option constant -name out -value “C:\temp\PrintAllSitesSubsites.csv”
    $spSite = [Microsoft.SharePoint.SPSite] ($siteURL)

    if($spSite -ne $null)
    {
    “Site Collection : ” + $spSite.Url | Out-File $out -Append
    foreach($subWeb in $spSite.AllWebs)
    {
    if($subWeb -ne $null)
    {
    #Print each Subsite
    #Write-Host $subWeb.Url
    “Subsite : ” + $subWeb.Name + ” – ” + $subWeb.Url | Out-File $out -append

    $spListColl = $subweb.Lists
    foreach($eachList in $spListColl)
    {
    if($eachList.Title -eq “Pages”)
    {
    $PagesUrl = $subweb.Url + “/”
    foreach($eachPage in $eachList.Items)
    {
    “Pages : ” + $eachPage[“Title”] + ” – ” + $PagesUrl + $eachPage.Url | Out-File $out -append
    }
    }
    }
    $subWeb.Dispose()
    }
    else
    {
    Echo $subWeb “does not exist”
    }
    }
    $spSite.Dispose()
    }
    else
    {
    Echo $siteURL “does not exist, check the site collection url”
    }
    Echo Finish

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s