PowerShell Script to Update a Field for Item and Descendant in Sitecore


Today I am going to share a script that can be used to update a particular field for the item and its descendants on the basis of the path provided in the script.

This script is powerful when you have to update a large number of items with common data.

$path = "/sitecore/content/Home"
$root = Get-Item $path
$items = Get-ChildItem $path -Recurse
($items += $root) | Where-Object { $_.Fields["Text"] -ne $null } | ForEach-Object {
    $_.Editing.BeginEdit()
    $_.Fields["Text"].Value = "Hello World";
    $_.Editing.EndEdit()
}

PowerShell scripts are useful as they are development accelerators that increase productivity and also decrease the time required to deliver a solution.




References


Sitecore PowerShell GitHub - https://github.com/SitecorePowerShell/Console
Chirag Goel

I am a developer, likes to work on different future technologies.

Post a Comment (0)
Previous Post Next Post