I am using Powershell to monitor a LOG file and filtering certain key words, need some help to put below lines all together and make it working as an automated task for alert.
Get-Content D:\temp\wow.log -Wait | where {$_ -match "TROUBLE CONNECTING!!"}
$LastWriteTime = (Get-Item $LogFile).LastWriteTime
$CurrentTime = Get-Date
$Range = (New-TimeSpan -Start $LastWriteTime -End $CurrentTime).TotalMinutes
Questions:
- How can I use
-wait
withif
the key words found - between the time range from
LastWriteTime
tillCurrentTime
- then, send a message.
I am trying to make it as a real time alert, not filtering the entire log but only the newest event.
If I want to schedule it as a task without output to screen, what are my options?
This is the message in the log file
WARN server comment 2021-06-11 02:21:01 - - - - - 2.0650160216E7 - - - - - - - - PushPublishRTMP.Reconnector[url]: TROUBLE CONNECTING!! Retrying in 60 seconds. app:live/_definst_