Last active
July 11, 2019 01:47
-
-
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.
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
$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 |
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
$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