I have a log file that I am trying parse through but haven't been able to find a solution. I've copied a portion of the log file below. Each group of 3 lines is one error.
csrak17 remove int_rpsmkt
Could not perform the administration request
Error: HPDMG1064E The group member was not found. (status 0x14c01428)
csrak17 add int_rpsops
Could not perform the administration request
Error: HPDMG1064E The group member was not found. (status 0x14c01428)
csrak17 remove int_rpssales
Could not perform the administration request
Error: HPDMG1064E The group member was not found. (status 0x14c01428)
csrak17 remove int_tpd
Could not perform the administration request
Error: HPDMG1064E The group member was not found. (status 0x14c01428)
csrak17 remove int_trpit
Could not perform the administration request
Error: HPDMG1064E The group member was not found. (status 0x14c01428)
I am loading the log file into an array and have no problem returning a line with an error code. What I need to do is first find a line with 'Error: HPDMG1064E' and then check the line two rows back to see if it has the word 'add' in it (like the second group example).
Is there a way to return a line in an array based on the value found in another? Of course I will be looping through the file and repeating the process.
Here's what I have so far but it only returns one line to my output file for some reason. Also, as you can see, I don't have any code for trying to find another index based on the current one.
$logs = Get-Content C:\Temp\test\ProdtamResults_HPDMG1064E_errors.doc
$Value = "HPDMG1064E"
foreach($log in $logs) {
$i = 0
while ($i -le $logs.length-1) {
if ($logs[$i] -match $Value)
{
return $logs[$i] | out-file C:\Temp\test\results.txt
}
$i++
}
}