I'm trying to send new lines added to a log file to slack if they have a certain word(s) in it - see in slack if I have errors.
What I hoped would work is:
$message = Get-Content '\\path\to\file.log' -Wait -Tail 0 | Select-String -Pattern 'ERROR'
foreach($line in $message) { Send-SlackMsg -Text "$($line)" -Channel $channel }
Sadly, it does not. I've replaced Send-SlackMsg with Write-Host just to see if that is the issue but it's not.
Get-Content '\\path\to\file.log' -Wait -Tail 0 | Select-String -Pattern 'ERROR'
Works like a charm in my console.
How can I make PowerShell perform an action when a new line appears and it matches the pattern?