SOLVED

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

%3CLINGO-SUB%20id%3D%22lingo-sub-901897%22%20slang%3D%22en-US%22%3ESharePoint%20Online%2FPnP%2FPowerShell%3A%20Update%20the%20workflow%20subscription%20by%20setting%20it%20to%20enabled%20to%20false%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-901897%22%20slang%3D%22en-US%22%3E%3CP%3EI%20try%20to%20update%20the%20%22Enabled%22%20property%20of%20a%20workflow%20subscription%20in%20SharePoint%20Online%20with%20PnP%20PowerShell%20but%20nothing%20append.%20My%20goal%20is%20to%20set%20programmaticaly%20this%20action%20as%20in%20UI%20when%20you%20can%20navigate%20to%20the%20Remove%20Workflow%20(RemWrkfl.aspx)%20page%20end%20then%20choose%20%22No%20New%20Instances%22.%20Here%20it%20is%20what%20I%20do%3A%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EImport-Module%20SharePointPnPPowerShellOnline%20-DisableNameChecking%3CBR%20%2F%3EConnect-PnPOnline%20-Url%20%22web_site_url%22%3CBR%20%2F%3E%24wfs%20%3D%20Get-PnPWorkflowSubscription%20-Name%20%22WF_Name%22%20-List%20%22Lists%2Flist_Name%22%3CBR%20%2F%3E%24wfs.Enable%20%3D%20%24false%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAfter%20this%20last%20command%2C%20I%20don't%20know%20what%20I%20need%20to%20do%20to%20activate%20this%20new%20property.%3C%2FP%3E%3CP%3ECan%20anyone%20help%20me%2C%20please%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-902343%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20Online%2FPnP%2FPowerShell%3A%20Update%20the%20workflow%20subscription%20by%20setting%20it%20to%20enabled%20to%20f%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-902343%22%20slang%3D%22en-US%22%3E%3CP%3EI%20finally%20found%20a%20solution%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%3E%24ctx%20%3D%20Get-PnPContext%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%3E%24lst%20%3D%20Get-PnPList%20-Identity%20%22Lists%2Flist_Name%22%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%3E%24wfs%20%3D%20Get-PnPWorkflowSubscription%20-Name%20%22WF_Name%22%20-List%20%24lst%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%3E%3CSTRONG%3E%24WorkflowServicesManager%20%3D%20New-Object%20Microsoft.SharePoint.Client.WorkflowServices.WorkflowServicesManager(%24ctx%2C%20%24ctx.Web)%3C%2FSTRONG%3E%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%3E%3CSTRONG%3E%24WorkflowSubscriptionService%20%3D%20%24WorkflowServicesManager.GetWorkflowSubscriptionService()%3C%2FSTRONG%3E%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%3E%3CSTRONG%3E%24ctx.Load(%24WorkflowServicesManager)%3C%2FSTRONG%3E%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%3E%3CSTRONG%3E%24ctx.Load(%24WorkflowSubscriptionService)%3C%2FSTRONG%3E%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%3E%3CSTRONG%3E%24ctx.ExecuteQuery()%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%3E%24wfs.Enabled%20%3D%20%24false%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%3E%3CSTRONG%3E%24WorkflowSubscriptionService.PublishSubscriptionForList(%24wfs%2C%20%24lst.Id)%20%7C%20Out-Null%3C%2FSTRONG%3E%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%3E%3CSTRONG%3E%24ctx.ExecuteQuery()%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20mixed%20PnP%20and%20CSOM%20(in%20bold).%3C%2FP%3E%3CP%3EMay%20be%20a%20more%20beautiful%20solution%20exists%2C%20but%20in%20this%20case%20it%20works.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
New Contributor

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?

1 Reply
Highlighted
Solution

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.