Monitoring rotating text files in real time with Powershell
So I needed a way to monitor some log files in a folder where a new log file gets created when the current one gets too large. All I'm interested in is checking the latest one for certain strings and then alerting if they occur. Powershell to the rescue: #folder to be watched $folder = 'C:\Temp\logger' #file types to be watched for $filter = '*.log' # <-- set this according to your requirements #strings to find in log $matchstring="My matching string" #variable to hold background powershell job $catjob #start a cat task as background process Function StartCat ($filepath) { #stop job is already monitoring a file if ($Global:catjob -ne $null) { stop-job -job $catjob remove-job -job $catjob } $scriptblock = { param ($file, $matchstring) cat $file -wait | ?{$_ -match $matchstring} } #start new job when file changed $Global:catjob = sta...