Changing Item Templates With Sitecore PowerShell

Mon Mar 19 2012

So I'm starting to explore the Sitecore PowerShell Console module from Adam Najmanowicz, and I think the community could benefit from a few more example scripts. I'm working on some enhancements to WeBlog that will allow you to more easily use different templates for each blog, which required me to change the template of a large number of entries. PowerShell made this easy once I figured it out:

$master = [Sitecore.Configuration.Factory]::GetDatabase("master");
$entryTemplate = $master.Templates["YouPhoria/Blog/Entry"];
cd master:\Content\Home\Blog\;
Get-ChildItem -recurse | ForEach-Object { if ($_.TemplateName -eq "BlogEntry") { $_.ChangeTemplate($entryTemplate) } };

And there you go.

Obligatory note: You could also do this using Revolver, a command prompt module from my WeBlog partner in crime Alistair Deneys.

Loading...
Nick Wesselman

Nick Wesselman started working professionally in software development just a few days after everyone realized we dodged a bullet with the Y2k bug. He’s worked as a Sitecore solution partner, Technology partner, and now for Sitecore itself. He lives with his wife, son, and daughter in Asheville, NC.