Skip to content

Instantly share code, notes, and snippets.

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 patelcp/1cf0925df7d08baa9ba4567ac83353bb to your computer and use it in GitHub Desktop.
Save patelcp/1cf0925df7d08baa9ba4567ac83353bb to your computer and use it in GitHub Desktop.
Find the fields used by a template, excluding the standard template fields in Sitecore PowerShell Extensions.
# Create a list of field names on the Standard Template. This will help us filter out extraneous fields.
$standardTemplate = Get-Item -Path "master:" -ID ([Sitecore.TemplateIDs]::StandardTemplate.ToString())
$standardTemplateTemplateItem = [Sitecore.Data.Items.TemplateItem]$standardTemplate
$standardFields = $standardTemplateTemplateItem.OwnFields + $standardTemplateTemplateItem.Fields | Select-Object -ExpandProperty key -Unique
# Change the Id to something other than the Sample Item template.
$itemTemplate = Get-Item -Path "master:" -ID "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}"
$itemTemplateTemplateItem = [Sitecore.Data.Items.TemplateItem]$itemTemplate
$itemTemplateFields = $itemTemplateTemplateItem.OwnFields + $itemTemplateTemplateItem.Fields | Select-Object -ExpandProperty key -Unique
$filterFields = $itemTemplateFields | Where-Object { $standardFields -notcontains $_ } | Sort-Object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment