I came across a scenario, where I need to update the email field for all custom forms built with ‘EmailTemplate’. Since it’s going to be a bulk update, decided to do it in SPE(so powerful!)
Here is the script I wrote –
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$path = "master:/sitecore/content/external_forms" | |
$templateName = "EmailTemplate" | |
$emailAddresses = "test@test.com" | |
$fieldName = "ToEmail" | |
$items = Get-ChildItem -Path $path -Recurse | Where-Object { $_.TemplateName -eq $templateName } | |
foreach($item in $items) { | |
if($item.Fields[$fieldName] -ne 'null'){ | |
$item.Editing.BeginEdit() | |
$item.Fields[$fieldName].Value = $emailAddresses | |
$item.Editing.EndEdit() | |
Write-Host ($item.Name + ": " + $item.Fields[$fieldName].Value) | |
} | |
} |
Hope this helps someone. Any questions, please leave a comment.
Happy Sitecoring!