Reputation: 51
I am currently using the following line of code to return the most recent line of a log via PowerShell
Get-Content -Path C:\folder\thisisalog.log -Tail 1 -Wait |
Where {$_ -match "Remote_http"}
This works correctly and will write to the console each time a log that matches "Remote_http" is logged.
However what I would like to do is run another script when this is returned.
So far I have tried to add to a variable and check if it is null with no luck and I have tried using if
statements with no success.
Trying both of these the script runs indefinitely with no output to console or triigers.
I think it may be something to do with -Wait
which is causing the issue.
Upvotes: 1
Views: 4744
Reputation: 17492
just do it
Get-Content -Path C:\folder\thisisalog.log -Tail 1 -Wait | % {if ($_ -match "Remote_http") {write-host "run code here"}}
or directly into your where
Get-Content -Path C:\folder\thisisalog.log -Tail 1 -Wait | where {if ($_ -match "Remote_http") {write-host "run code here"}}
Upvotes: 5