I was trying to search a string in logs that will update continuously in every second.
So i wrote the code to search the string if the string found in log it will triger an email.
and created the tasks in task scheduler to run the script in every 5 min.
But the issue is that if script found the "string" in log it will trigger mail in every 5 min continuoisly beause script is checking whole log file everytime.
Can you please suggest me is this possible to point last script checked the logs till the point and next time script will run and do not check whole log file it will check only from last script done.
Select-String doesn't have anything built in that would do what you want. I can think of a couple of ways I might do this, but none of them are going to perform very well if this file is large. I might look into using Get-Content with the -Tail option, to try and grab only the most recent lines from the file. You'd have to have some way of figuring out how many lines had been added since last time, I guess – I'm not sure how you'd go about that since I don't know what the log file contents look like.