Publishing Pages

Get SharePoint Publishing Pages with PowerShell

Posted on Updated on

This code is to get all publishing pages that is created in the last 30 days.
It is compatible will all On-Prem SharePoint 2007, 2010, 2013 and 2016
Please open PowerShell-ISE and put the code in it. then click Run


$ErrorActionPreference = "SilentlyContinue"
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Publishing")
#Start-SPAssignment -Global
$newline = [Environment]::NewLine
$webAppURL="https://yoursharepointwebapplication.com"
$currentWebApplication = [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($webAppURL)
$sites = $currentWebApplication.Sites
foreach($Site in $sites)
{
if ($Site.ServerRelativeUrl.Contains("market")){
#$Site = New-Object Microsoft.SharePoint.SPSite($SiteUrl)
$PubSite = New-Object Microsoft.SharePoint.Publishing.PublishingSite($Site)
$PubPageCount = 0
$newPubPageCount = 0
$ImageCount = 0
$DocCount = 0
foreach ($Web in $Site.AllWebs) {
$PubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($Web)
$Pages = $PubWeb.GetPublishingPages($PubWeb)
foreach ($Page in $Pages)
{
if($Page.CreatedDate -GT (Get-Date).AddDays(-30))
{
$newPubPageCount += 1
}
}
$PageCount = $Pages.Count
$PubPageCount = $PubPageCount + $PageCount
#$Images = $PubWeb.ImagesLibrary.ItemCount
#$ImageCount = $ImageCount + $Images
#$Documents = $PubWeb.DocumentsLibrary.ItemCount
#$DocCount = $DocCount + $Documents
$Web.Dispose()
}
$OutputList += $Site.Url + "," + $Site.Allwebs.Count + "," + $PubPageCount + "," + $newPubPageCount +";"
$Site.Dispose()
#Stop-SPAssignment -Global
}
}
$OutputList

Advertisements