Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcelgruber/2bfb04326269af5c7d5d03c059b50431 to your computer and use it in GitHub Desktop.
Save marcelgruber/2bfb04326269af5c7d5d03c059b50431 to your computer and use it in GitHub Desktop.
Database Refresh Post Step For Item Field Value Updates With Environment Selector
$options = @{
"DEV"="DEV"
"STAGE"="STAGE"
}
$props = @{
Parameters = @(
@{Name="selectedOption"; Title="Choose an environment"; Options=$options}
)
Title = "Environment selector"
Description = "Restore values for which environment?"
Width = 300
Height = 300
ShowHints = $false
}
$result = Read-Variable @props
if($result -ne "ok")
{
Exit
}
Write-Host "Selected environment: $($selectedOption)"
Write-Host ""
$isDev = $selectedOption -eq "DEV"
$Restorable = @(
@{
"fPath"="master://sitecore/content/path/to/item";
"field"="FieldName";
"updatedVal"=
if ($isDev)
{"dev value"}
else
{"stage value"};
},
@{
"fPath"="master://sitecore/content/path/to/item2";
"field"="FieldName";
"updatedVal"=
if ($isDev)
{"dev value"}
else
{"stage value"};
})
foreach ($restore in $Restorable){
$item = Get-Item -Path $restore.fPath -language en
Write-Host "Updating item: $($item.ID) $($restore.fPath)"
Write-Host "Updating field: $($restore.field)"
Write-Host "--"
Write-Host "From:"
Write-Host "$($item[$($restore.field)])"
Write-Host ""
$item.Editing.BeginEdit()
$item["$($restore.field)"] = "$($restore.updatedVal)"
$item.Editing.EndEdit() | Out-Null
Write-Host "To:"
Write-Host "$($item[$($restore.field)])"
Write-Host "----------------------------------------"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment