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
Get-Content -Path $logFile -wait | ?{$_-match "$filter"}
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 ?
Pipe it to a foreach loop, which will go through each line individually, and you can put the if statement in the loop:
Get-Content -Path $logFile -wait | %{if($_ -match "$filter"){Callfunction}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With