Skip to content

Instantly share code, notes, and snippets.

@AdamNaj
Last active February 6, 2017 13:21
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 AdamNaj/3b1f7c9519c3c36ecb8ccbe5401f3966 to your computer and use it in GitHub Desktop.
Save AdamNaj/3b1f7c9519c3c36ecb8ccbe5401f3966 to your computer and use it in GitHub Desktop.
Template Usage Audit script
$templates = [Sitecore.Data.Managers.TemplateManager]::GetTemplates((Get-Database "master"))
$templates | %{
if($_ -ne $null -and -not ($_.GetType().Name -match "ErrorRecord") -and -not ($_.Value.FullName.StartsWith("System"))){
try {
$template = $_.Value
$templateItem = Get-Item master:\ -ID $template.ID
$items = @() + (Get-ItemReferrer -Database "master" -ID $template.ID | ? { $template.Name -ne "__Standard Values"})
Add-Member -InputObject $templateItem -MemberType NoteProperty -Name "FullName" -Value ($template.FullName)
} catch {
Add-Member -InputObject $templateItem -MemberType NoteProperty -Name "UsageCount" -Value "Error getting references"
return $templateItem
}
Add-Member -InputObject $templateItem -MemberType NoteProperty -Name "UsageCount" -Value ($items.count)
return $templateItem
}
} |
Sort-Object UsageCount -Descending |
Show-ListView -Property FullName, UsageCount
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment