PJ,
I don’t have your log to test but, some of your logic is a little hard to follow. Here’s what I think should work.
$SawLog = Get-Content "C:\temp\Complete.log"
$FullSelect += $SawLog -match "Part( Started -| Complete)|PRT(0004|0005|0009)|ENG(0029|0037)|OPR0078|WaitingForPrinterTrigger"
$GetData = $False
$Results = foreach ($line in ($FullSelect -split [environment]::NewLine)) {
if ($line -match 'Part Started -') {
#Start flag to gather data, reset array and reset $trap flag
$GetData = $True
$ProcessArray = @()
$Trap = $False
}
if ($GetData) {
#Return the line and check for error to set trap
if ($line -match "PRT(0004|0005|0009)|ENG(0029|0037)|OPR0078|WaitingForPrinterTrigger") {
$trap = $True
}
$ProcessArray += $line
}
if ($line -match "Part Complete") {
#reset the get data flag
$GetData = $False
if ($Trap) { $ProcessArray }
}
}
$Results