0

We have over a thousand approval workflows running and I would like to write a PowerShell script to go through and approve the items from the system account. I already wrote the script to get the correct workflow tasks from the "Workflow Tasks" library but when I try and set those tasks to approved they don't seem to fully update. Here are the Properties I am currently setting:

$task[[Microsoft.SharePoint.SPBuiltInFieldId]::WorkFlowVersion]=1
$task["Outcome"] = "Approve"
$task["Status"] = "Completed"
$task["% Complete"] = 1
$task["ApprovalOutcome"] = 2
$task["TaskStatus"] = "Approved"
$task["Decision"] = 2
$task["Completed"] = $true
$task.Systemupdate()

This seems to set the workflow as complete from the list view but when you go into the workflow task properties the "Primary Approval Status" and Approval Status fields are still in a pending state. The workflow also does not see the task as complete. The fields in the list view show it as complete though, for instance the "Status" field shows "Completed, the "% Complete" field shows "100%, the "Outcome" field shows "Approve"

Has anyone ever used PowerShell to approve workflow approval tasks? It should be noted we are actually using Nintex workflows but I am pretty sure the workflow Approval task behaves the same as an out of the box workflow would.

3
  • I wonder if permissions could be a factor. the task is assigned to another user but I am running the code from the system account? Any thoughts on that?
    – kds6253
    Feb 13, 2014 at 18:44
  • 1
    I'm marking this as off topic as it is a Nintex question. This should be addressed at connect.nintex.com. Feb 13, 2014 at 21:13
  • As far as I understand Nintex it is just a wrapper on top of the existing SharePoint Workflow infrastructure. That is why I thought I could address the issue here as a share point designer workflow issue.
    – kds6253
    Feb 13, 2014 at 21:36

1 Answer 1

1

Try this extra bit of powershell with the $task object:

$ht = new-object Hashtable 
$ht["TaskStatus"] = "Approved" 
[Microsoft.SharePoint.Workflow.SPWorkflowTask]::AlterTask($task, $ht, $false)
3
  • I've just changed to a C# console App and used that code. Now the workflow that contains the task is showing the folowing message "Because of heavy load, the latest workflow operation has been delayed." any ideas?
    – kds6253
    Feb 13, 2014 at 17:26
  • As seen on the following link, that problem happens when using a C# app, but won't happen via powershell: sharepointblogs.be/blogs/vandest/archive/2011/06/28/…
    – tyshock
    Feb 13, 2014 at 17:29
  • I tried it with PowerShell and it just seems to change the task to "In Progress". it doesn't get approved though.
    – kds6253
    Feb 13, 2014 at 17:49

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