Changing Item Templates With Sitecore PowerShell
Posted 3/19/2012 by techphoria414
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.
Comments
-
Adam Najmanowicz said:
3/20/2012 5:01 AM
Hi Nick,
I was meaning to do more of those, unfortunately didn't have much time to devote to teh subject lately.
I absolutely love that you find the plugin useful and look forward to your feedback and findings! I think a lot of those would be easier if I added a bit more Sitecore specific commandlets, e.g. "Get-ItemTemplate" could be quite handy in your scenario.
However - I agree for the moment I think the best thing to do is coming up with a good library of samples developers can use and learn from modifying - great job on that one!