Include PowerShell Workflow Scripts in a Workflow

158 Views Asked by At

I have several Workflow scripts defined. I want to write a master script to reference the dependent scripts. I am expecting there is some kind of Import or Include statement to reference the dependent scripts and make the workflows available.

How do I make this work ?

Example: dependent.ps1

workflow doSomething
{
   Write-Output "Hello World"
}

master.ps1:

Import dependent.ps1
workflow master
{
   doSomething
}
1

There are 1 best solutions below

1
Mark Wragg On

You can include the contents of another script in to your script via dot sourcing:

. .\dependent.ps1

workflow master
{
   doSomething
}

You could use a loop to do this for several scripts and even use Get-ChildItem to discover them programmatically:

$ScriptsToInclude = Get-ChildItem \path\to\your\scripts\*.ps1

ForEach ($Script in $ScriptsToInclude.Fullname) {
   . $Script
}