Last active
May 18, 2023 17:24
-
-
Save MartinMiles/59e79d76d811811ee7da08830bca9762 to your computer and use it in GitHub Desktop.
SPE script used for evaluation of rendering of the solution assets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
write-host 'Running script...' | |
Set-Location master:\content | |
$pages = get-item 'master:\content\Site or Tenant' | get-childitem -Recurse | |
$device = Get-LayoutDevice -Default | |
$Results = @(); | |
foreach($page in $pages){ | |
$renderings = Get-Rendering -Item $page -Device $device -FinalLayout | |
foreach($rendering in $renderings){ | |
if($rendering.ItemID -ne $null) | |
{ | |
$renderingItem = Get-Item master: -ID $rendering.ItemID | |
$dataSourceItem = $null | |
$pageTemplate = Get-ItemTemplate -Item $page | |
if (![string]::IsNullOrEmpty($rendering.Datasource)) | |
{ | |
$datasourcePath = $rendering.Datasource | |
if ($datasourcePath.StartsWith("local:")) { | |
$datasourcePath = $datasourcePath.Replace("local:", $page.Paths.FullPath) | |
#"datasourcePath: " + $datasourcePath | |
$dataSourceItem = Get-Item -Path "master:$datasourcePath" -ErrorAction SilentlyContinue | |
} | |
else { | |
$guidRegex = '\b[A-F0-9]{8}(?:-[A-F0-9]{4}){3}-[A-F0-9]{12}\b' | |
if ($datasourcePath -match $guidRegex) { | |
$dataSourceItem = Get-Item master: -ID $datasourcePath | |
} else { | |
$dataSourceItem = Get-Item -Path "master:$datasourcePath" -ErrorAction SilentlyContinue | |
} | |
} | |
} | |
if($renderingItem -ne $null) | |
{ | |
$Properties = @{ | |
RenderingItemName = $renderingItem.Name | |
RenderingItemID = $renderingItem.ID | |
DataSource = $rendering.Datasource | |
DataSourcePath = $dataSourceItem.Paths.Path | |
RenderingItemPath = $renderingItem.Paths.Path | |
ControllerAction = $renderingItem."Controller Action" | |
ViewPath = $renderingItem.Path | |
UsedOnPage = $page.Name | |
UsedOnPageID = $page.ID | |
UsedOnPagePath = $page.Paths.Path | |
PageTemplate = $pageTemplate.Name | |
PageTemplateId = $pageTemplate.ID | |
} | |
$Results += New-Object psobject -Property $Properties | |
} | |
} | |
} | |
} | |
$Results | Show-ListView -Property RenderingItemName,RenderingItemID,RenderingItemPath,Datasource,DataSourcePath,ControllerAction,ViewPath,UsedOnPage,UsedOnPageID,UsedOnPagePath,PageTemplate,PageTemplateId | |
write-host 'Script ended' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment