Inventory of Page Layout Usage in a SharePoint Site
Recently I got a request to find out the usage of page layouts on a large SharePoint site. I Googled and found a few scripts, but none that did all I wanted, e.g. to limit the inventory to a certain sub-site. So I wrote my own one.
functionGet-PageLayoutsInUse{[CmdletBinding()]Param([Parameter(Mandatory=$true)][string]$SiteUrl,[Parameter(Mandatory=$false)][string]$MatchUrlPart)Add-PSSnapin"Microsoft.SharePoint.PowerShell"-ErrorActionSilentlyContinue$objSite=Get-SPSite$SiteUrl[Microsoft.Sharepoint.Publishing.PublishingSite]$publishingSite=New-ObjectMicrosoft.SharePoint.Publishing.PublishingSite($objSite)$layoutsInUse=@()if([Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($publishingSite.RootWeb)-eq$true){$pageLayouts=$publishingSite.GetPageLayouts($false)foreach($layoutin$pageLayouts){Write-Host"Looking for references to "$layout.ServerRelativeUrl[Microsoft.SharePoint.SPFile]$file=$publishingSite.RootWeb.GetFile($layout.ServerRelativeUrl);if($MatchUrlPart){$links=$file.BackwardLinks|where {$_.ServerRelativeUrl-like$MatchUrlPart}}else{$links=$file.BackwardLinks}$layoutReportItem=@{Title=$layout.Title;File=$layout.ServerRelativeUrl;Count=$links.Count}$newobject=New-ObjectPSObject-Property$layoutReportItem$layoutsInUse+=$newobject}}$a=@{Expression={$_.LayoutName}}$layoutsInUse|Sort-ObjectCount-Descending|Select-Object-Property*}
This has been tested in a SharePoint 2013 on-prem farm run locally on a server in the farm. If run from C: it can be used like this and exported to CSV for the entire site: