August 28, 2013

List all pages using specific Page Layout

clear
   1:  Add-PsSnapin Microsoft.SharePoint.PowerShell
   2:  filter Get-PublishingPages
   3:  {
   4:                  $pubweb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($_)
   5:      $query = new-object Microsoft.SharePoint.SPQuery
   6:                  $query.Query = "<Where><In><FieldRef Name='PublishingPageLayout' /><Values><Value Type='URL'>/_catalogs/masterpage/<Layout1.aspx></Value><Value Type='URL'>/_catalogs/masterpage/<Layout2.aspx></Value><Value Type='URL'>/_catalogs/masterpage/<Layout3.aspx></Value></Values></In></Where>"
   7:     
   8:                  $query.ViewAttributes = "Scope='Recursive'"
   9:      $pubweb.GetPublishingPages($query)   
  10:  }
  11:   
  12:  $str = Read-Host "Enter Site URL: "
  13:   
  14:  if($str -eq $null )
  15:  {
  16:                  Write-Host "Enter a valid URL"
  17:                  return
  18:  }
  19:   
  20:  $site = Get-SPSite -Identity $str
  21:  if($site -eq $null)
  22:  {
  23:                  Write-Host "Enter a valid URL"
  24:                  return
  25:  }
  26:   
  27:  $allweb = $site.Allwebs
  28:  foreach($web in $allweb )
  29:  {
  30:      $web | Get-PublishingPages | select Uri, Title, @{Name='PageLayout';Expression={$_.Layout.ServerRelativeUrl}}| Format-List
  31:  }

If you have any questions you can reach out our SharePoint Consulting team here.

No comments:

Post a Comment