How it works...
The first step in the script is to read the contents of the log file. Get-Content reads the content, each line in the file being a separate element in a string array. Next, we initialize the variable that will contain our object. We use the foreach loop construct to perform operations on each of the log lines.
Now to a single log entry. The first thing we do here is split the log at whitespace, and pick the first element in it, because the structure of the log line tells us that the timestamp is in the beginning. We use the split method within the string object and pick the timestamp.
Next, we perform a couple of simple string replacement operations (or the single alternative operation) using the replace operator (or Select-String ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access