I encountered a production issue where a deployment change had released several items to production where newly created content folders were of the wrong template type.
Rather than crawling the entire content tree from /Sitecore/Content, the solution leveraged the Find-Item function to query the Sitecore index. Results from Find-Item are of type Sitecore.ContentSearch.SearchType.SearchResultItem.
The Solution
To resolve the template mismatch, the process involved two steps:
- Retrieve items using
Get-Item $id - Apply the
ChangeTemplatemethod to reassign the correct template
$items = Find-Item -Index sitecore_master_index -Criteria @{Filter = "Equals"; Field = "_template"; Value = "wrong-template-id"}
foreach($item in $items) {
$sitecoreItem = Get-Item -Path "master:" -ID $item.ItemId
$newTemplate = Get-Item -Path "master:" -ID "correct-template-id"
$sitecoreItem.ChangeTemplate($newTemplate)
}