Is it possible to terminate or stop a PowerShell pipeline from within a filter

后端 未结 8 2186
無奈伤痛
無奈伤痛 2020-12-06 06:27

I have written a simple PowerShell filter that pushes the current object down the pipeline if its date is between the specified begin and end date. The objects coming down

8条回答
  •  清歌不尽
    2020-12-06 06:35

    It is not possible to stop an upstream command from a downstream command.. it will continue to filter out objects that do not match your criteria, but the first command will process everything it was set to process.

    The workaround will be to do more filtering on the upstream cmdlet or function/filter. Working with log files makes it a bit more comoplicated, but perhaps using Select-String and a regular expression to filter out the undesired dates might work for you.

    Unless you know how many lines you want to take and from where, the whole file will be read to check for the pattern.

提交回复
热议问题