0

We are trying to refactor few of the Sitecore templates. We need some help with powershell script. Is there any way to pull bunch of fields (around 70-80) to different template sections. Manual pull is taking lots of time. Can we do this through powershell?

1

Let's say you start with a template like the following:

enter image description here

Then the following script will move items to a newly created section like this:

enter image description here

Using this sample, you can build in whatever logic you want. Keep in mind that if you are wanting to move fields between templates then you need to change the inheritance first.

# Get the template I want to change
$templateId = "{F8BC7158-5A2F-40FE-A7D9-453229EC325E}"
$selectedTemplate = Get-Item -Path "master:" -ID $templateId

$currentChildren = $selectedTemplate.Children
$count = $currentChildren.Count + 1

# Add a new template section
$templateSectionId = "{E269FBB5-3750-427A-9149-7AA950B49301}"
$newSection = New-Item -Parent $selectedTemplate -Name "Section$($count)" -ItemType $templateSectionId

# Move fields
foreach($currentChild in $currentChildren) {
    $child = $currentChild.Children[0] | Initialize-Item
    Write-Host "Moving $($child.ItemPath)"
    Move-Item -Path $child.ItemPath -Destination $newSection.ItemPath
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.