How to change the workflow in existing items using the PowerShell Script?
Published: 27 September 2023



But the already existing item will not be affected. Because Sitecore never changes existing items by itself.

Solution:
To apply the new workflow to existing items We can use the Powershell script.

Script:

In this script add the location after "$contentsToUpdate = Get-Item master: -Query" to apply workflow likewise in my case all items under the home will be updated to the new workflow.
In "$content.Fields["__Default workflow"].Value" and "$content.Fields["__Workflow"].Value" add your workflow Item Id.
In "$content.Fields["__Workflow state"].Value" add your workflow default status Id.

When the Script runs successfully it returns the "True" value for each item and the workflow will apply to all items otherwise it returns the "False" value.

Mitesh Patel - Technical Head - ADDACT
Sitecore || XMCloud || OrderCloud Certified
Mitesh, a distinguished Technical Head at Addact/Addxp, is a prominent figure in Sitecore/XMCloud/OrderCloud certified writing. From Sitecore XM Cloud Developer Certification to Sitecore 10 .NET Developer Certification and Sitecore OrderCloud Certification, Mitesh's expertise is unparalleled. Mitesh is not only a skilled Sitecore CMS developer but also a 12+ years experienced software engineer proficient in various technologies such as MVC, ASP.Net, C#, jQuery, and Azure cloud/AWS.