Skip to content

Instantly share code, notes, and snippets.

@kpatil-hi
Created January 8, 2021 18:38
Show Gist options
  • Save kpatil-hi/a2e8866c7333ff11de1f939b68ff90a9 to your computer and use it in GitHub Desktop.
Save kpatil-hi/a2e8866c7333ff11de1f939b68ff90a9 to your computer and use it in GitHub Desktop.
Remove from Workflow
$props = @{
InfoTitle = "Remove workflows"
PageSize = 10000000
}
Write-Host "Starting work in the context of the 'master' database, under /Home item."
Set-Location -Path "master:/sitecore/content/<YOURNODE>"
# Set up variables
$workflowState1 = "{13FDC8BC-60B9-44E1-ADCC-CED02E0392A9}" #ID of the workflow states. DRAFT
$workflowState2 = "{E4B3ADA1-FB0D-449E-80BF-3B4EFFBFF3CA}" # Awaiting Approval
$workflowState3 = "{0B80F300-9C48-4FC5-B59B-90F7B0D56832}" #Approved
function Remove-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 = ""
$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
}
}
}
}
$items = Remove-Workflows
$items | Show-ListView @props -Property ItemPath, ID, @{Label="Language"; Expression={$_."Language"}}
Close-Window
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment