我想要做的是获得一个功能,以便在达到时间限制时停止管道馈送.我创建了一个测试函数,如下所示:
function Test-PipelineStuff { [cmdletbinding()] Param( [Parameter(ValueFromPipeLIne=$true)][int]$Foo,[Parameter(ValueFromPipeLIne=$true)][int]$MaxMins ) begin { "THE START" $StartTime = Get-Date $StopTime = (get-date).AddMinutes($MaxMins) "Stop time is: $StopTime" } process { $currTime = Get-Date if( $currTime -lt $StopTime ){ "Processing $Foo" } else{ continue; } } end { "THE END" } }@H_502_3@这一定会阻止管道,但是它从不称为“end {}”块,在这种情况下,这个块是至关重要的.有人知道为什么当我停止使用“继续”的管道时,我的“end {}”块不被调用?如果我抛出一个PipelineStoppedException,行为似乎是一样的.
根据
about_Functions:
原文链接:https://www.f2er.com/javaschema/281431.html@H_502_3@After the function receives all the objects in the pipeline,the End@H_502_3@因此,你只需要省略else块.然后管道中的所有对象都被处理,但是由于if子句,实际的处理只有在时间限制被触发之前才进行处理.
statement list runs one time. If no Begin,Process,or End keywords
are used,all the statements are treated like an End statement list.