PowerShell工作流学习-1-嵌套工作流和嵌套函数
关键点:
a)嵌套深度没有任何语法限制,但是嵌套三个层次的工作流不支持任何通用参数,包括工作流通用参数
b)嵌套工作流可以调用当前范围和任何父范围内的工作流和函数
c)工作流不允许递归调用,脚本和函数中允许进行递归调用
d)工作流和函数名称仅可在每个工作流中使用一次。 名称冲突会生成错误,
e)如果嵌套工作流或函数的名称与父范围内的工作流或函数的名称相同,则对该名称的调用将调用当前工作流范围内的工作流或函数
例a:
workflow test-wf3 { "One" Two workflow Two { "Two" Three Function Three { "Three" function Five {"Five"} Workflow Four {"Four"; Five} Four } } } PS C:\Windows\system32> test-wf3 One Two Three Four Five
例b:
function Zero {"Zero"} workflow One { "One" Two Three Four workflow Four { "Four"; Two; Three; Five; workflow Five {"Five"; Two; Three; Zero} } } function Two {"Two"} workflow Three {"Three"} PS C:\Windows\system32> function Zero {"Zero"} workflow One { "One" Two Three Four workflow Four { "Four"; Two; Three; Five; workflow Five {"Five"; Two; Three; Zero} } } function Two {"Two"} workflow Three {"Three"} PS C:\Windows\system32>One One Two Three Four Two Three Five Two Three Zero
例c:
workflow one { "One" Two } workflow two { "Two" One } 所在位置 行:1 字符: 1 + workflow one + ~~~~~~~~~~~~ 工作流无法使用递归。 + CategoryInfo : ParserError: (:) [], ParseException + FullyQualifiedErrorId : RecursiveWorkflowNotSupported
例d:
workflow Test-Workflow { workflow Test1 {"Test1"} function Test1 {"Hello, Test1"} } + function Test1 {"Hello, Test1"} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The function or workflow 'Test1' cannot be redefined. + CategoryInfo : ParserError: (:) [], ParseException + FullyQualifiedErrorId : FunctionRedefinitionNotAllowed
例e:
function Test-Nested {"Test-Nested Function"} workflow Test-Workflow { Workflow Test-Nested {"Test-Nested Workflow"} Test-Nested } PS C:\>Test-Workflow Test-Nested Workflow