Last active
September 20, 2023 18:06
-
-
Save keyan1603/ddfc36061c7c7819782af7530d5f5548 to your computer and use it in GitHub Desktop.
Sitecore SPE Script to update workflow states under specific node
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
Write-Host "Starting work in the context of the 'master' database, under /sitecore/content/website1/Data item." | |
Set-Location -Path "master:/sitecore/content/website1/Data" | |
# Set up variables | |
$workflowState1 = "{xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" #ID of the workflow states. | |
$workflowState2 = "{yyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy}" | |
$workflowState3 = "{zzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz}" | |
function Update-Workflows { | |
# Logic | |
foreach ($item in Get-ChildItem . -Recurse) | |
{ | |
foreach ($version in $item.Versions.GetVersions($true)) | |
{ | |
if (($version.Fields["__Workflow state"].Value -eq $workflowState1) -or ($version.Fields["__Workflow state"].Value -eq $workflowState2) -or ($version.Fields["__Workflow state"].Value -eq $workflowState3)) | |
{ | |
$version.Editing.BeginEdit(); | |
$version.Fields["__Workflow state"].Value = "{aaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa}" | |
$version.Editing.EndEdit(); | |
#Publish-Item $version -Target "web" -PublishMode SingleItem -Language $version.Language | |
Write-Host $version.ID " - " $version.Language | |
$version; | |
} | |
else | |
{ | |
#Write-Host "NOT UPDATED: " $version.ItemPath " - " $version.Language | |
} | |
} | |
} | |
} | |
Update-Workflows |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment