To add OOTB 2010 workflow to SharePoint List by CSOM .
Get the List of SharePoint 2010 Workflow Templates by using the below method
webObj.WorkflowTemplates
I needed the Approval workflow. So i get it by its name after finding out in previous method.
$wfApprovalWFTemplate = webObj.WorkflowTemplates.GetByName("Approval - SharePoint 2010")
Note:
When getting the list of workflows using the Workflow Service Manager Class will return only all those WF's created by SP2013 . i.e Through Workflow Manager.
Create a Workflow Association info
$wfassociationInfo = New-Object Microsoft.SharePoint.Client.Workflow.WorkflowAssociationCreationInformation;
$wfassociationInfo.Template = $wfApprovalWFTemplate;
$wfassociationInfo.Name = "Document Approval"
$wfassociationInfo.TaskList ="#Task List to Assign"
$wfassociationInfo.HistoryList = "#WF History List to Assign"
Associate to the Document Library where you want the approval WF to be added .
Write-Host "Create a new Workflow Associationg with the Neccesary information."
$wf = $listWFToAdd.WorkflowAssociations.Add($wfassociationInfo)
$wf.AutoStartChange = $true
$wf.AutoStartCreate = $true
$wf.AssociationData = $customAssociationData //XML data to store WF Options--You can loop through and get this value from existing workflows to get the structure and settings done.
$wf.Update();