Sitecore Powershell Extension Script For Setting Workflows

Posted 09/26/2016 by Ed Kapuscinski

I recently needed to apply a workflow to a site after the site has been built. This is an annoying (but relatively straightforward) process. The first step was setting the workflow I needed in all of the appropriate standard values items. I know this doesn't retroactively apply workflows to existing items (we have another tool for that), but this was how to begin.

The good news, because I'm a lazy developer, is that the Sitecore PowerShell Extensions ISE makes this very easy!

Here's the command I created to do the job. Simple, quick and dirty. In my case, the {D0F3BBA7-06D6-43E8-8759-2CF73BDA3D60} GUID is the ID of the workflow I want to set as default.

(Get-Item master: -Query "/sitecore/templates/Project/ProjectName//*[@@name='__Standard Values']")| ForEach-Object {
      $_.Editing.BeginEdit()     $_.Fields["__Default workflow"].Value = "{D0F3BBA7-06D6-43E8-8759-2CF73BDA3D60}";     $_.Editing.EndEdit()

I thought this might be helpful because, while I found all the knowledge about what to combine to do it out there on the internet, I didn't see it all put together in the way I needed. Hopefully I've put enough keywords in this that Google will help you find it if you need to do the same thing.


Add your comment