Search code examples
powershellpowershell-workflow

"Invoking" Powershell workflow from a script


I am pretty new to Powershell and Powershell Workflows. In all the Workflow examples I've seen on the internet, the workflow is "defined" and "invoked" from the same file, like below:

workflow test-workflow {
    $random = 1
    $random
}

test-workflow

This is a pretty lame example where the workflow simply prints the value "1". What I want to do is define the workflow in a file called say "test-workflow.ps1" and invoke it from another Powershell script file called say "test-script.ps1". Is that possible?


Solution

  • Dot-source the script with the workflow implementation in your other script:

    . C:\path\to\workflow.ps1
    
    Test-Workflow