Powershell if statement in pipeline

Question:

I am in need to create a script which can continuously read a file and if a certain line with text comes, to call a function.

I am thinking in a way to do this a single line thing with

but I am not aware of a way to call a function if the line does answer the criteria.

Is that doable ? or I should do it like in a loop to read the file every cycle and if there is a match to exit the loop ?

Answer:

Pipe it to a foreach loop, which will go through each line individually, and you can put the if statement in the loop:

Source:

Powershell if statement in pipeline by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply