The log file contains:
===== SMTP_server_not_set_up @PANEL SMTP server not set up. Contact system administrator. @PAGECNT 381 @SCANADFCNT 0 @DATETIME 2019-08-29T10:05:51-0400 @UPTIME 0:00:23 @CODELVL Base MSNGM.053.023 Engine GM.052.E015 Panel f0.12p48v3 @END ===== PowerOnReset @PAGECNT 381 @SCANADFCNT 0 @DATETIME 2019-08-29T10:05:50-0400 @PORCNT 49 @CODELVL Base MSNGM.053.023 Engine GM.052.E015 Panel f0.12p48v3 @END ===== Load_MP_Feeder_with_Custom_Type_5_Letter @PANEL Load MP Feeder with Custom Type 5 Letter @PAGECNT 337 @SCANADFCNT 0 @DATETIME 2019-08-29T09:59:22-0400 @UPTIME 0:44:15 @CODELVL Base MSNGM.053.023 Engine GM.052.E015 Panel f0.12p48v3 @END =====
... many many more lines
I want to grab the 6 lines following the line "=====" and turn that into a custom object.
For example, based on the first lines, the ideal object would be:
MESSAGE: SMTP_server_not_set_up PANEL : @PANEL SMTP server not set up. Contact system administrator. PAGECNT: @PAGECNT 381 SCANADFCNT :@SCANADFCNT 0 DATETIME : @DATETIME 2019-08-29T10:05:51-0400 UPTIME: @UPTIME 0:00:23
So far I can isolate those 6 lines that follow the recurring "=====" like this:
(Select-String -Path "$PSScriptRoot\$($printer)_history.log" -Pattern "=====" -Context 6).Context.PostContext
Now I need to put those lines in the custom object. I really don't know exactly how to approach this correctly, I'm exploring doing something like this:
$ObjHistory = @()
(Select-String -Path "$PSScriptRoot\$($printer)_history.log" -Pattern "=====" -Context 6).Context.PostContext | ForEach-Object {
if ($_ -match "PANEL") {
$properties = [ordered]@{'PANEL'="$_"}
$objet = New-Object -TypeName PSObject -Property $properties
}
$ObjHistory += $objet
}
$ObjHistory
This way I found out I can put that PANEL property in a custom object sucessfully, it outputs:
PANEL ----- @PANEL SMTP server not set up. Contact system administrator. @PANEL Load MP Feeder with Custom Type 5 Letter @PANEL Load MP Feeder with Custom Type 5 Letter @PANEL Load MP Feeder with Custom Type 5 Letter @PANEL Load MP Feeder with Custom Type 5 Letter
However, I need to do that for the other lines and I'm stuck at how to approach it, since ForEach-Object
does one line at a time.