Ensure_List_ContentType_WorkflowAssociation_Enabled

useful for disabling (or re-enabling) existing workflow associations
Language:
PowerShell
Keywords:
SharePoint
Code Snippet

## Ensures that a Workflow is Associated to a Content Type.. if it does, do nothing; if it does not, add it
Function Ensure_List_ContentType_WorkflowAssociation_Enabled( [Microsoft.SharePoint.SPContentType]$tContentType
                                                            , $wfAssociationName
                                                            , $wfEnabled
                                                            ) {
   #if ($tContentType.WorkflowAssociations.GetAssociationByBaseID($tWorkflowTemplate.BaseId) -eq $null) {
    $tWorkflowAssociation = $tContentType.WorkflowAssociations.GetAssociationByName($wfAssociationName, [System.Globalization.CultureInfo]::CurrentCulture)
    if ($tWorkflowAssociation -eq $null -and
        $tWorkflowAssociation.Enabled -ne $wfEnabled) {
        $tWorkflowAssociation.Enabled = $wfEnabled
        Write-Output([System.String]::Format("Content Type [{0}] Workflow Association [{1}] : Setting Enabled to [{2}]", $tContentType.Name, $wfAssociationName, $wfEnabled))
        $tContentType.UpdateWorkflowAssociation($tWorkflowAssociation)
    }
} # Function Ensure_List_ContentType_WorkflowAssociation_Enabled(...)


Created 2011-10-13
comments powered by Disqus
Login