Here's one way to process a log file.
$AllTasks = @()
$entries = @()
$log = Get-Content c:\temp\x.txt
$capture = $false
foreach ($row in $log) {
if ($row.StartsWith("End of task")) { # look for whatever indicates an end
$capture = $false
$AllTasks += [PSCustomObject]@{
ID = $taskid
Messages = $entries
}
$entries = @()
}
if ($capture) {
$entries += $row
}
if ($row.StartsWith("Start of task")) { # look for whatever indicates a start
$capture = $true
$taskid = $row.Substring(13).trim() # whatever comes after start of task
}
}
"Processing done."
"We found {0} tasks." -f $AllTasks.count
foreach ($task in $AllTasks) {
"Task id is {0}" -f $task.id
foreach ($msg in $task.Messages) {
" {0}" -f $msg
}
}
Based on what you posted, it should produce this output.
Processing done.
We found 2 tasks.
Task id is 1
Number of errors:0
Task id is 2
ERR something went wrong
ERR another thing went wrong
Number of errors: 2