I have made a Powershell script to run workflow on SharePoint 2010. The workflow manager assignment is the only part of the script with a null value.

$listName = "Action Tracking System"
$Site = Get-SPsite "https://intranet.xxx.xxx.xxx/depts/FSO" | GEt-SPweb
$List = $Site[1].lists[$listname]
$manager = $site[1].workflowmanager
$Association  = $list.WorkflowAssociations[5]    #30 Day Reminder workflow
$association.AllowAsyncManualStart = $true
$association.AllowManual = $true

$data = $Association.AssociationData
foreach ($Item in $list.Items)
    Write-Host "    Content: " $Item.Name
    $wf = $manager.StartWorkflow($Item,$association,$data)

It returns you cannot call a method on a null value expression (char 27).

The site is a subsite of FSO, the $site[1] index shows the correct site. How can I start this workflow?


The code is wrong. The following is what you need to start a SharePoint 2010 workflow.

$ListName = 'Action Tracking System';
$WorkflowName = '30 Day Reminder';

$Web = Get-SPWeb 'https://intranet.xxx.xxx.xxx/depts/FSO';
$List = $Web.Lists[$Listname];
$Items = $List.GetItems();

$Manager = $Web.Site.WorkflowManager;
$Association = $List.WorkflowAssociations.GetAssociationByName($WorkflowName, 'en-US');
$Data = $Association.AssociationData;

foreach ($Item in $Items)
    Write-Host 'Content: ' $Item.Name;
    $WF = $Manager.StartWorkflow($Item, $Association, $Data, $true);

  • thanks, I tried it out and with one modification it worked, the $web portion did not work because it is a subsite, so I left that my original code with $site. but the line for $association was all that I needed to change. I was running each line by line in powershell, that is why I forgot to add the semicolons. But now it submits my workflow item by item. And I can schedule the ps1 in task scheduler as Farm admin. Hope that works out. Thanks for the help. The msdn docs sometimes don't provide the correct language and you can't expose workflow methods easily. – MEV Apr 26 '17 at 15:33
  • Glad I could help. Note that the semicolons are not mandatory in PowerShell. I use them because I use them in any other language I work with, and because I think it makes the script more readable. – Mihail-Florin Popa Apr 26 '17 at 15:40
  • Mihail, I am able to submit the workflow, but it returns an error of categoryinfo: not specified. Just to check, I ran the workflow from the same item from the URL and it completed successfully. I did at $true as fourth parameter to startworkflow step. – MEV Apr 26 '17 at 19:08
  • Also, when I expose $manager is show nothing. Even though $Association shows correct workflow, and $item show correct item, and $data has info. – MEV Apr 26 '17 at 19:14
  • This error is usually related to permissions. I suggest you use a site collection administrator to execute the PowerShell script. – Mihail-Florin Popa Apr 27 '17 at 10:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.