Forum Discussion

francois77's avatar
francois77
Copper Contributor
Oct 09, 2019
Solved

SharePoint Online/PnP/PowerShell: Update the workflow subscription by setting it to enabled to false

I try to update the "Enabled" property of a workflow subscription in SharePoint Online with PnP PowerShell but nothing append. My goal is to set programmaticaly this action as in UI when you can navi...
  • francois77's avatar
    Oct 09, 2019

    I finally found a solution:

     

    $ctx = Get-PnPContext
    $lst = Get-PnPList -Identity "Lists/list_Name"
    $wfs = Get-PnPWorkflowSubscription -Name "WF_Name" -List $lst

    $WorkflowServicesManager = New-Object Microsoft.SharePoint.Client.WorkflowServices.WorkflowServicesManager($ctx, $ctx.Web)
    $WorkflowSubscriptionService = $WorkflowServicesManager.GetWorkflowSubscriptionService()
    $ctx.Load($WorkflowServicesManager)
    $ctx.Load($WorkflowSubscriptionService)
    $ctx.ExecuteQuery()

    $wfs.Enabled = $false

    $WorkflowSubscriptionService.PublishSubscriptionForList($wfs, $lst.Id) | Out-Null
    $ctx.ExecuteQuery()

     

    I mixed PnP and CSOM (in bold).

    May be a more beautiful solution exists, but in this case it works.

Resources