我正试图从InlineScript
块内暂停工作流程:
workflow foobar {
Param([string]$Choice)
InlineScript {
switch ($Using:Choice)
1 { Write-Host "One!" }
2 { Write-Host "Two!" }
3 { Write-Host "Suspending worklflow!"; Suspend-Workflow }
}
}
}
使用foobar -Choice 3
调用工作流程会返回错误:
The term Suspend-Workflow is not recognized as the name of a cmdlet, function, script file, or operable program.
是否可以通过这种方式拨打Suspend-Workflow
?怎么样?
答案 0 :(得分:2)
不可以从inlinescript暂停工作流程。挂起需要能够序列化所有执行状态。工作流引擎的设计是为了做到这一点,但基本的PowerShell引擎却没有。
答案 1 :(得分:1)
根据此博客文章,工作流程不支持Switch语句:
https://blogs.technet.microsoft.com/heyscriptingguy/2013/01/02/powershell-workflows-restrictions/
修改强>
也许嵌套的If就足够了?
workflow foobar {
Param([string]$Choice)
if ($choice -eq 1) {
InlineScript {Write-Host "One!"}
}
if ($choice -eq 2) {
InlineScript {Write-Host "Two!" }
}
elseif ($choice -eq 3) {
Suspend-Workflow
}
}