在工作流中包括PowerShell工作流脚本

时间:2019-05-02 13:32:11

标签: powershell powershell-workflow

我定义了几个工作流程脚本。 我想编写一个主脚本来引用从属脚本。 我期望有某种类型的Import或Include语句引用相关脚本并使工作流可用。

我如何进行这项工作?

示例: dependent.ps1

workflow doSomething
{
   Write-Output "Hello World"
}

master.ps1:

Import dependent.ps1
workflow master
{
   doSomething
}

1 个答案:

答案 0 :(得分:1)

您可以通过dot sourcing将另一个脚本的内容包含到脚本中:

. .\dependent.ps1

workflow master
{
   doSomething
}

您可以使用循环对多个脚本执行此操作,甚至可以使用Get-ChildItem以编程方式发现它们:

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

ForEach ($Script in $ScriptsToInclude.Fullname) {
   . $Script
}
相关问题