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 therefoe 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.

 

 

Advertisements