none
Add workflow to contenttype by share-point power shell script RRS feed

  • Question

  • Hello,

      I need to add work flow "Publish Approval" to content type by SharePoint power shell script .

      how Can I implement that ?


    ASk

    Sunday, May 25, 2014 3:35 PM

Answers

  • Hi,

    According to your post, my understanding is that you want to add the workflow to a content type using PowerShell script.

    The following PowerShell script for your reference:

    function AddWorkflowToContentType($site, $ctName, $WfName, $WfAssociationName, $TaxTaskList)
    {
        [void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SharePoint')
        [void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.Office.Policy')
        [Guid]$wfTemplateId = New-Object Guid
        $web = $site.RootWeb
        $ct = $web.ContentTypes[$ctName]
        $culture = New-Object System.Globalization.CultureInfo("en-US")
        $template = $site.RootWeb.WorkflowTemplates.GetTemplateByName($WfName, $culture)
        if($template -ne $null)
        {
            $tasklist = $TaxTaskList
            $historylist = "IP Workflow History"
            # Workflow Association with Content Type
            $association = [Microsoft.SharePoint.Workflow.SPWorkflowAssociation]::CreateSiteContentTypeAssociation($template, $WfAssociationName, $web.Lists[$tasklist], $web.Lists[$historylist])
            $association.AllowManual = $false
            $association.AutoStartCreate = $true
            $ct.AddWorkflowAssociation($association)
            $ct.UpdateWorkflowAssociationsOnChildren($true, $true, $true, $false)
            $association.Enabled=$true
            $ct.Update()
            $web.Update()
        }
        else
        {
            Write-Error "Workflow Template not found"
            Add-Content $logFileName "Workflow Template not found."
        }
    }
    

    More information is here:
    http://anujabhojani.blogspot.com/2013/04/powershell-to-attach-workflow-on.html

    Best Regards


    Dennis Guo
    TechNet Community Support

    • Marked as answer by himo Tuesday, May 27, 2014 2:26 PM
    Tuesday, May 27, 2014 11:25 AM
    Moderator

All replies

  • Hi

    How to add a workflow to a list or document library

    http://blogs.msdn.com/b/guruketepalli/archive/2012/11/06/add-remove-sharepoint-workflows-thru-powershell.aspx

    If you need to do it for a specific content type,

    first you should find that content type

    http://techtrainingnotes.blogspot.ro/2011/01/powershell-to-find-sharepoint-content.html

    and next apply to it with some changes as for a  list/library


    Romeo Donca, Orange Romania (MCSE, MCITP, CCNA) Please Mark As Answer if my post solves your problem or Vote As Helpful if the post has been helpful for you.

    Sunday, May 25, 2014 8:01 PM
  • Hi,

    According to your post, my understanding is that you want to add the workflow to a content type using PowerShell script.

    The following PowerShell script for your reference:

    function AddWorkflowToContentType($site, $ctName, $WfName, $WfAssociationName, $TaxTaskList)
    {
        [void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SharePoint')
        [void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.Office.Policy')
        [Guid]$wfTemplateId = New-Object Guid
        $web = $site.RootWeb
        $ct = $web.ContentTypes[$ctName]
        $culture = New-Object System.Globalization.CultureInfo("en-US")
        $template = $site.RootWeb.WorkflowTemplates.GetTemplateByName($WfName, $culture)
        if($template -ne $null)
        {
            $tasklist = $TaxTaskList
            $historylist = "IP Workflow History"
            # Workflow Association with Content Type
            $association = [Microsoft.SharePoint.Workflow.SPWorkflowAssociation]::CreateSiteContentTypeAssociation($template, $WfAssociationName, $web.Lists[$tasklist], $web.Lists[$historylist])
            $association.AllowManual = $false
            $association.AutoStartCreate = $true
            $ct.AddWorkflowAssociation($association)
            $ct.UpdateWorkflowAssociationsOnChildren($true, $true, $true, $false)
            $association.Enabled=$true
            $ct.Update()
            $web.Update()
        }
        else
        {
            Write-Error "Workflow Template not found"
            Add-Content $logFileName "Workflow Template not found."
        }
    }
    

    More information is here:
    http://anujabhojani.blogspot.com/2013/04/powershell-to-attach-workflow-on.html

    Best Regards


    Dennis Guo
    TechNet Community Support

    • Marked as answer by himo Tuesday, May 27, 2014 2:26 PM
    Tuesday, May 27, 2014 11:25 AM
    Moderator