Unable to resume a workflow via task scheduler

Question:

In a powershell window I run the following workflow:

Then to resume the workflow, I have the following scheduled via task scheduler triggered to run at startup:

The workflow does not get resumed neither at startup, nor if I manually trigger it via Task Scheduler. The contents of zqqfff.txt indicates that the task scheduler activated powershell cannot see the workflow. A regular powershell window can see the workflow when I run Get-Job.

(Both the normal powershell window and the task scheduler powershell instance run as same user.)

I used procmon to see what’s going on and I can see from this that when powershell normally vs taskscheduler it’s looking at different workflow persistence paths, namely:

C:\Users\weijgerss\AppData\Local\microsoft\windows\PowerShell\WF\PS\default\S-1-5-21-3519956147-933941082-741972881-500_EL (a normal powershell window uses this folder)
C:\Users\weijgerss\AppData\Local\microsoft\windows\PowerShell\WF\PS\default\S-1-5-21-3519956147-933941082-741972881-500_EL_NI (a task scheduler activated powershell instance uses this folder)

I’m totally stumped. How can I get a task scheduler activated powershell instance to see the same workflows as normal powershell window can?

Answer:

The below scripts give you a solution that automatically resumes powershell workflows after a reboot/crash using task scheduler at system start up:

resume-workflows.ps1: (the first line below fixes the _NI issue mentioned in the question)

resume-workflows.cmd: (works around a windows 8/server 2012 task scheduler bug)

To put it all together use the following powershell script to shedule resume-workflows.cmd to run at system start up:

Enjoy!

(ILSpy, sysinternal’s procmon, plenty of google and a dash of windbg were all instrumental in bringing the above answer to you)

Source:

Unable to resume a workflow via task scheduler by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply