Sitecore Powershell to update item fields


The Powershell module is one of the flexible ways to work with the Sitecore items with ease. If you have not installed the module yet, i highly recommend installing the Sitecore Powershell Extensions module from the Sitecore Marketplace

Here is a code snippet to update the Sitecore item fields:

New-UsingBlock (New-Object Sitecore.Data.BulkUpdateContext) {
foreach($item in Get-ChildItem -Path master:\content\MyWebsite\Folder01 -Recurse) {
$item.Editing.BeginEdit()
$item.Roles = “{C731475E-D7BF-4BE1-A323-9C059ED2DE49}|{CC6FEF3F-8C13-4EC7-8E5A-9F0E56769FED}”
$item[“__Workflow state”] = “{4785314C-2C4A-4784-955B-D638CB42E994}”
$item.Editing.EndEdit() | Out-Null
}
}

The above script will be recursive and can reach items in the subfolder level. You could remove the “-Recurse” parameter if you are looking at the child items for the current folder.

The above script can scale to any other field updates or any other item or set of item updates.

 

Feel free to leave a reply here...

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s