Skip to main content

get item paths by template id

This PS script will iterate over the id/name kvp provided and output a list of Sitecore items that use the given template; grouped by template.

$templatesToRemove = @{
"{00000000-0000-0000-0000-000000000000}", = "Template 1"
"{00000000-0000-0000-0000-000000000000}", = "Template 2"
"{00000000-0000-0000-0000-000000000000}", = "Template 3"
}

# Get all items in the content tree
$items = Get-ChildItem -Path "/sitecore/content/Confused/" -Recurse

foreach($templateId in $templatesToRemove.Keys)
{
Write-Output $templatesToRemove[$templateId]

# Filter the items by template
$itemsUsingTemplate = $items | Where-Object { $_.TemplateId -eq $templateId }

# Output the item paths
$itemsUsingTemplate | ForEach-Object { Write-Host $_.Paths.Path }

Write-Output "-------------------------"
}