Powershell Logo

Changing Item Templates With Sitecore PowerShell

Posted 3/19/2012 by techphoria414

Posted in

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.

Share:

Add your comment

 
 

 

Comments

  • Adam Najmanowicz's gravatar 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!

  • Nick Wesselman's gravatar Nick Wesselman said:
    3/20/2012 8:36 AM

    Hey that's what the community is for, right? Some more commandlets for common tasks would definitely help. I was thinking that some workflow commandlets in particular could be useful for some scenarios that I've run into... get state, set state, is final, etc. Nice job on this plugin.

Sitecore MVP

Syndication

Recent comments