Forum Discussion
francois77
Oct 09, 2019Copper Contributor
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 navigate to the Remove Workflow (RemWrkfl.aspx) page end then choose "No New Instances". Here it is what I do:
Import-Module SharePointPnPPowerShellOnline -DisableNameChecking
Connect-PnPOnline -Url "web_site_url"
$wfs = Get-PnPWorkflowSubscription -Name "WF_Name" -List "Lists/list_Name"
$wfs.Enable = $false
After this last command, I don't know what I need to do to activate this new property.
Can anyone help me, please?
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.
1 Reply
Sort By
- francois77Copper Contributor
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.