2

Is there a PowerShell script that would pull up the pages in a site collection?

2 Answers 2

2

Try the below script

##If you use SharePoint 2010 PowerShell, this is not required
[System.Reflection.Assembly]::Load(“Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”)
[System.Reflection.Assembly]::Load(“Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”)

$siteURL = "http://localhost/"
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

Read more here:https://tjendarta.wordpress.com/2013/03/19/powershell-to-loop-through-all-sharepoint-sites-and-pages/

For all site collections in a web application then check this http://www.sharepointfix.com/2012/02/powershell-script-to-enumerate-sites.html

1
  • Thanks Waqas - this script seems to work. Cheers!
    – Vader
    Dec 20, 2016 at 22:17
1

Try the following PowerShell code to list the pages within all Pages Libraries in a site collection

$siteCollectionUrl = "http://epm/"
$site =new-object Microsoft.SharePoint.SPSite($siteCollectionUrl)
$query = new-object Microsoft.SharePoint.SPSiteDataQuery
$query.Webs = "<Webs Scope='SiteCollection'>"
$query.Lists = "<Lists ServerTemplate='850' />"
$results = $site.rootweb.GetSiteData($query)
foreach($row in $results.rows)
{
  $listId = $row["ListId"]
  $webId = $row["WebId"]
  $childWeb = $site.OpenWeb([GUID]($webId))
  $pagesList = $childWeb.Lists[[GUID]($listId)];
  $itemUrl = $childWeb.Url + "/" + $pagesList.RootFolder.Url


  foreach($eachPage in $pagesList.Items)
  {
    "AllPages : " + $eachPage["Title"] + " - " + $PagesUrl + $eachPage.Url

  }

  $childWeb.Dispose()
}
$site.Dispose()

Output

enter image description here

For more details check List all Pages Libraries using PowerShell and SPSiteDataQuery?

2
  • Qassas- is this script suppose to show the list of pages under a SC? i changed the URL and ran it, no errors but didn't provide the results at all. Where I'm I supposed to find them. I don't see anything on the script specifying an export location.
    – Vader
    Dec 20, 2016 at 22:14
  • 1
    you are right, I forget to loop for pages, now it should be working as my mentioned screenshot, hope it helped you :) Dec 20, 2016 at 22:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.