Skip to content

Instantly share code, notes, and snippets.

@michaellwest
Last active January 9, 2022 22:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save michaellwest/f8d47e8662c51dc7d2ea30e2988fd902 to your computer and use it in GitHub Desktop.
Save michaellwest/f8d47e8662c51dc7d2ea30e2988fd902 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