A workflow cannot use recursion

Welcome Forums General PowerShell Q&A A workflow cannot use recursion

Viewing 5 reply threads
  • Author
    Posts
    • #80423
      Participant
      Topics: 34
      Replies: 88
      Points: 41
      Rank: Member

      I have the code below which has been fine until I installed V5.1 of PS. Now everytime I load the module with this code I get the recursion error. Cant figure out why it has changed…

    • #80575
      Participant
      Topics: 0
      Replies: 669
      Points: 0
      Rank: Member

      I ran your code in a Windows 2016 domain – PowerShell 5.1 – and it worked.

      Test-Connection uses the Win32_PingStatus WMI class and requires a DCOM connection to the remote machine. I’d suggest testing Test-Connection against one of the failing remote machines directly rather than in the workflow. I’d also suggest that you test get-WMIObject against the failing machine to help determine if there is a DCOM issue

      • #80644
        Participant
        Topics: 34
        Replies: 88
        Points: 41
        Rank: Member

        The code works. The problem is that when I load the module that has the above code in it I get the ‘A workflow cannot use recursion’ error. Don’t know its giving me that error when the code actually works.

    • #80741
      Participant
      Topics: 0
      Replies: 669
      Points: 0
      Rank: Member

      Do you call the workflow within the module code?

    • #81637
      Participant
      Topics: 34
      Replies: 88
      Points: 41
      Rank: Member

      No – the module is imported at the start of an external script and the workflow is launched from there.
      This code has not changed – it just started showing this ‘error’ since V5 or 5.1 of WMF.

    • #83147
      Participant
      Topics: 34
      Replies: 88
      Points: 41
      Rank: Member

      It appears to be a bug. I just removed the workflow from my module.

    • #243179
      Participant
      Topics: 0
      Replies: 4
      Points: 46
      Rank: Member

      It appears you can use workflows with modules with v5.1 and later but it requires a bit of a trick.

       

      I posted this same solution SO: https://stackoverflow.com/questions/45183731/using-a-recursive-function-beside-a-workflow

       

      For example, this workflow can be used to start/stop service in parallel:

      If you put this in your psm1 file and try to import it, it will fail with this error:

      To embed this in the module, do NOT put it in the .psm1 file, create a separate ps1 file and place it in the module folder.
      e.g. Invoke-ServiceInParallelWF.ps1

      Then in your manifest (psd1) file, modify the ScriptsToProcess to include the ps1 file.

      Finally, import your module and test the function:

      • This reply was modified 2 months, 1 week ago by kvprasoon.
      • This reply was modified 2 months, 1 week ago by kvprasoon. Reason: Merge to a closed thread
Viewing 5 reply threads
  • You must be logged in to reply to this topic.