0

I've got a small string to look at a log file for any instances of the word Error and also added a count of how many time this occurs in said log file.

( Get-Content "C:\Users\mchalmer\Desktop\ControlOIS.log" | Where-Object { $_.Contains("ERROR") } ).Count

I would like to know if it's possible to get the string of text after the Error word was detected?

Here is a small snipped of the Log file for context:

2017-10-01 05:37:51:109 - ERROR: [Service App] Unable to start worker process, Error performing "LogonUser", error code: 87. "The parameter is incorrect"

What I would like to do is set up a way to grab all errors with the relevant string from the log file and dump out in a file for me so I can quickly see what needs to be fixed.

henrycarteruk
  • 12,708
  • 2
  • 36
  • 40
  • 1
    See the linked duplicate, Mark. It's a really common mistake for beginners of PowerShell (the `-contains` operator works on collections, not on individual strings). The other questions has all the explanations and alternatives and what they do :) – briantist Jan 22 '18 at 16:00
  • Great, thank you, I will take a look. – Mark Chalmers Jan 22 '18 at 16:11

0 Answers0