Skip to content

Instantly share code, notes, and snippets.

@nehemiahj
Created September 17, 2021 18:38
Show Gist options
  • Save nehemiahj/f84079f17915c0053b8a443550fa1460 to your computer and use it in GitHub Desktop.
Save nehemiahj/f84079f17915c0053b8a443550fa1460 to your computer and use it in GitHub Desktop.
Sitecore PowerShell - List all referenced items by lookup items
<#
.SYNOPSIS
Lists all referenced items by lookup items.
.NOTES
NEHEMIAH JEYAKUMAR
#>
#
# INPUT / CONFIGURATION
#
$props = @{
Title = "Lists all referenced items By Lookup Items"
Description = "Lists all referenced items By Lookup Items"
OkButtonName = "Run Report"
CancelButtonName = "Cancel"
Parameters = @(
@{ Name = "lookupRootItem"; Title = "Lookup Item Root Folder"; Editor = "droptree"; Source = "/sitecore/Content/" }
@{ Title = "Note"; Value = "Select the root (folder) of the Lookup Items."; Editor = "info" }
)
}
$result = Read-Variable @props
if($result -ne "ok") {
Close-Window
Exit
}
filter Where-HasGetReferencePages{
param([Parameter(Mandatory=$TRUE,ValueFromPipeline=$TRUE)][Sitecore.Data.Items.Item]$item)
$linkDb = [Sitecore.Globals]::LinkDatabase
$referredItems = $linkDb.GetReferrers($item)
foreach($rItem in $referredItems) {
$pageItem = Get-Item -Path "master:" -ID $rItem.SourceItemID
New-Object PSObject @{ LookupItemTitle = $item.Name; PageName = $pageItem.Name; PagePath = $pageItem.Paths.FullPath; PageItem = $pageItem }
}
}
#Start Executing the Report
$lookupItems = Get-ChildItem -Path master: -ID $lookupRootItem.ID -Recurse | Where-HasGetReferencePages
if ($lookupItems.Count -eq 0)
{
Show-Alert "Did not find any items with forms";
}
else
{
# Setup a hashtable to make a more readable script.
$props = @{
InfoTitle = "Pages List"
InfoDescription = "Lists all pages with item reference"
PageSize = 25
}
$lookupItems | Show-ListView @props -Property `
@{ Label = "Lookup Item Name"; Expression = { $_.LookupItemTitle } },
@{ Label = "Page Name"; Expression = { $_.PageName } },
@{ Label = "Page Path"; Expression = { $_.PagePath} },
@{ Label = "Template"; Expression = { $_.PageItem.TemplateName} }
}
Close-Window
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment