Today I tried to start a workflow using PowerShell and I got this annoying error:
Exception calling “StartWorkflow” with “4” argument(s): “”
At C:\Users\spsetup\Downloads\StartDocumentLocksWF.ps1:38 char:9
+ $wf = $wfm.Startworkflow($item,$association, $data,$true)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SPException
I knew that I was doing the right thing as this worked for another workflow:
$ver = $host | select version if($Ver.version.major -gt 1) { $Host.Runspace.ThreadOptions = "ReuseThread" } if(!(Get-PSSnapin Microsoft.SharePoint.PowerShell -ea 0)) { Write-Progress -Activity "Loading Modules" -Status "Loading Microsoft.SharePoint.PowerShell" Add-PSSnapin Microsoft.SharePoint.PowerShell } # Settings $siteUrl = "https:/ /intranet.mycomp.com/admin" $web = Get-SPWeb $siteUrl $list = $web.Lists["Docs"]; #-- Getting a Workflow manager object to work with. $wfm = $web.Site.WorkFlowManager #-- Getting the subscriptions $association = $list.WorkFlowAssociations |Where { $_.Name -eq "Handle Document Locks"} $data = $association.AssociationData $wc=new-object system.net.webclient $wc.UseDefaultCredentials = $true foreach ($item in $list.Items) { Write-Host $item["Title"] $item.ContentType.Name if ($item.ContentType.Name -eq "My Document") { $wf = $wfm.Startworkflow($item,$association, $data,$true) Start-Sleep -Seconds 10 } }
I am not doing anything complicated, just starting a workflow. The workflow that I was starting however didn’t have manual start enabled and therefore I wasn’t able to start it with PowerShell either.
Enabling the manual start and then republishing the workflow and all worked as expected.
Note: the same error message will also appear when the workflow is already started.
Thanks for the comments about requiring manual start & that the workflow cannot be currently running. Was testing this step as part of a script to stop & restart the workflow, and overlooked the fact that I hadn’t stopped the running instance for my test! Good catch, and useful info I didn’t find elsewhere.