diff --git a/Data/serialization/master/sitecore/system/Modules/PowerShell/Script Library/Examples/Content Maintenance/Mass Change Item Templates.item b/Data/serialization/master/sitecore/system/Modules/PowerShell/Script Library/Examples/Content Maintenance/Mass Change Item Templates.item new file mode 100644 index 000000000..bb90787f5 --- /dev/null +++ b/Data/serialization/master/sitecore/system/Modules/PowerShell/Script Library/Examples/Content Maintenance/Mass Change Item Templates.item @@ -0,0 +1,79 @@ +----item---- +version: 1 +id: {50456B81-0FB3-4705-BC61-E6FDD2CF98A3} +database: master +path: /sitecore/system/Modules/PowerShell/Script Library/Examples/Content Maintenance/Mass Change Item Templates +parent: {F25BF203-F58F-4F3C-B017-3ACD2F063479} +name: Mass Change Item Templates +master: {00000000-0000-0000-0000-000000000000} +template: {DD22F1B3-BD87-4DB2-9E7D-F7A496888D43} +templatekey: PowerShell Script + +----version---- +language: en +version: 1 +revision: 1b5da6d3-8bcd-4f41-ba0f-ce0b04c88320 + +----field---- +field: {B1A94FF0-6897-47C0-9C51-AA6ACB80B1F0} +name: Script +key: script +content-length: 1505 + +<# +Based on Blog by @Techphoria414 - Nick Wesselman +http://www.techphoria414.com/Blog/2012/March/Change-Item-Templates-With-Sitecore-PowerShell +#> + +$sourceTemplate = get-item 'master:\templates\Sample\Sample Item' +$targetTemplate = get-item 'master:\templates\Sample\Sample Item' +$branch = get-item . +$result = Read-Variable -Parameters ` + @{ Name = "branch"; Title="Branch to work on"; Root="/sitecore/"; Tooltip="Items you want to work on."}, ` + @{ Name = "sourceTemplate"; Title="Current template"; Root="/sitecore/templates/"; Tooltip="Template you want to replace."}, ` + @{ Name = "targetTemplate"; Title="New template"; Root="/sitecore/templates/"; Tooltip="Template you want to use."} ` + -Description "This report will replace template on all items in the tree with another template of your choice" ` + -Title "Branch Template Replace" -Width 500 -Height 400 ` + -OkButtonName "Replace" -CancelButtonName "Cancel" + +if($result -ne "ok") +{ + Exit +} + +$path = $branch.ProviderPath; +cd $branch.ProviderPath; +$targetTemplateItem = New-Object -TypeName "Sitecore.Data.Items.TemplateItem" -ArgumentList $targetTemplate +Write-Host "For branch '$($branch.ProviderPath)' changing templates from '$($sourceTemplate.Name)' to '$($targetTemplate.Name)'" +Get-ChildItem $path -recurse | Where-Object{$_.TemplateID -eq $sourceTemplate.ID} | ForEach-Object { $_.ChangeTemplate($targetTemplateItem); Write-Host "Changing $($_.ProviderPath)" }; + +Show-Result -Text -Width 800 -Height 700 +Close-Window +----field---- +field: {25BED78C-4957-4165-998A-CA1B52F67497} +name: __Created +key: __created +content-length: 15 + +20130902T111843 +----field---- +field: {8CDC337E-A112-42FB-BBB4-4143751E123F} +name: __Revision +key: __revision +content-length: 36 + +1b5da6d3-8bcd-4f41-ba0f-ce0b04c88320 +----field---- +field: {D9CF14B1-FA16-4BA6-9288-E8A174D4D522} +name: __Updated +key: __updated +content-length: 34 + +20130902T111843:635137175234032422 +----field---- +field: {BADD9CF9-53E0-4D0C-BCC0-2D784C282F6A} +name: __Updated by +key: __updated by +content-length: 14 + +sitecore\admin diff --git a/PowerShellIntegrations/Commandlets/Interactive/ReadVariableCommand.cs b/PowerShellIntegrations/Commandlets/Interactive/ReadVariableCommand.cs index c73947a19..c9e0f6d34 100644 --- a/PowerShellIntegrations/Commandlets/Interactive/ReadVariableCommand.cs +++ b/PowerShellIntegrations/Commandlets/Interactive/ReadVariableCommand.cs @@ -1,6 +1,7 @@ using System.Collections; using System.Management.Automation; using Cognifide.PowerShell.PowerShellIntegrations.Commandlets.Interactive.Messages; +using Sitecore.Data.Items; using Sitecore.Jobs.AsyncUI; namespace Cognifide.PowerShell.PowerShellIntegrations.Commandlets.Interactive @@ -85,7 +86,12 @@ protected override void ProcessRecord() { foreach (Hashtable result in results) { - SessionState.PSVariable.Set((string) result["Name"], result["Value"]); + object resultValue = result["Value"]; + if (resultValue is Item) + { + resultValue = ItemShellExtensions.GetPsObject(SessionState, resultValue as Item); + } + SessionState.PSVariable.Set((string)result["Name"], resultValue); } } });