Workflow with pipeline

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Mike F Robbins Mike F Robbins 2 years, 7 months ago.

  • Author
    Posts
  • #14876
    Profile photo of Pratik Patel
    Pratik Patel
    Participant

    I have following powershell script:

    function Testing
    {
        [CmdLetBinding()]
        Param (                
            [int]$MaxRetrycount = 3,
            [Parameter(ValueFromPipeline=$True)] [String]$Definition
        )   
        return $MaxRetrycount
    }
    
    workflow Test-Workflow
    {
        $PSComputerName
    
        $data = 'abc','xyz'
        $data | Testing -MaxRetrycount 2 -Definition
        $JobName
    }
    
    Test-Workflow
    

    But execution of this script giving me error like

    
    The 'Testing' activity is not supported in a workflow pipeline.
    

    Did I make any mistake in calling function with command pipeline from workflow?

    Thanks in advance.

  • #15142
    Profile photo of Mike F Robbins
    Mike F Robbins
    Participant

    When a workflow is run in PowerShell, it's processed by Windows Workflow Foundation (WWF) which translates the PowerShell commands into WWF Activities. Since your Testing function doesn't have an equivalent WWF activity, that means it can't be used in a workflow unless it's placed inside of an inline script block.

    
    workflow Test-Workflow {
        $PSComputerName
    
        $data = 'abc','xyz'
    
        InlineScript {
            $data | Testing -MaxRetrycount 2
        }
    
        $JobName
    }
    

    Supposedly, the Testing function would need to be in the same script file as the workflow or be placed in a module. I was only able to make it work by placing the Testing function inside of a module that's located in one of the $env:PSModulePath paths that's available to all users, although I didn't spend a lot of time trying to make it work the other way either.

You must be logged in to reply to this topic.