Skip to content

Instantly share code, notes, and snippets.

@michaellwest
Last active July 11, 2019 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaellwest/7692a5b881afb3737fe26dd8d0b1a3cb to your computer and use it in GitHub Desktop.
Save michaellwest/7692a5b881afb3737fe26dd8d0b1a3cb to your computer and use it in GitHub Desktop.
Find all template fields where the source is not empty using Sitecore PowerShell Extensions.
$watch = [System.Diagnostics.Stopwatch]::StartNew()
$path = "/sitecore/templates/Project"
$templateId = "{AB86861A-6030-46C5-B394-E8F99E8B87DB}"
$templateFieldId = "{455A3E98-A627-4B40-8035-E683A0331AC7}"
$db = Get-Database -Name "master"
$rootItem = $db.GetItem($path)
$templates = $rootItem.Axes.GetDescendants() |
Where-Object { $_.TemplateId -eq $templateId } | Initialize-Item
$reportItems = [System.Collections.ArrayList]@()
foreach($template in $templates) {
$templateFields = $template.Axes.GetDescendants() |
Where-Object { $_.TemplateId -eq $templateFieldId } |
Where-Object { ![string]::IsNullOrEmpty($_.Fields["Source"].Value) }
foreach($templateField in $templateFields) {
$reportItem = @{
"Template Name" = $template.Name
}
$reportItem["ID"] = $templateField.ID
$reportItem["Field Name"] = $templateField.Name
$reportItem["Field Source"] = $templateField.Fields["Source"].Value
$reportItems.Add([PSCustomObject]$reportItem) > $null
}
}
$watch.Stop()
$watch.ElapsedMilliseconds
$reportItems | Show-ListView
$path = "/sitecore/templates/Project"
$templateId = "{AB86861A-6030-46C5-B394-E8F99E8B87DB}"
$templateFieldId = "{455A3E98-A627-4B40-8035-E683A0331AC7}"
$templates = Get-ChildItem -Path $path -Recurse |
Where-Object { $_.TemplateId -eq $templateId }
$reportItems = [System.Collections.ArrayList]@()
foreach($template in $templates) {
$templateFields = Get-ChildItem -Path "master:" -ID $template.ID -Recurse |
Where-Object { $_.TemplateId -eq $templateFieldId } |
Where-Object { ![string]::IsNullOrEmpty($_.Fields["Source"].Value) }
foreach($templateField in $templateFields) {
$reportItem = @{
"Template Name" = $template.Name
}
$reportItem["ID"] = $templateField.ID
$reportItem["Field Name"] = $templateField.Name
$reportItem["Field Source"] = $templateField.Fields["Source"].Value
$reportItems.Add([PSCustomObject]$reportItem) > $null
}
}
$reportItems | Show-ListView
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment