Hi jacob,
You could try something like this:
$str = @"
2013-11-17, 17:12:01
Condition: dest_path (\\Server\Folder) does not exist or is not a directory
An error log was created and stored as:
C:/bin/../errors/1117171200004132.log
The global configuration ‘SMTPserver’ property is not set or is set to an invalid value.
No alert email was sent.
2013-11-17, 17:12:02
Condition: ftp communication problem. Host: rpconnect.redprairie.net
An error log was created and stored as:
C:/live/bin/../errors/1117171200004132.log
The global configuration ‘SMTPserver’ property is not set or is set to an invalid value.
No alert email was sent.
"@
$array = $str -split [System.Environment]::NewLine
$i = 0
$array | foreach{$i++;if($_ -eq "No alert email was sent."){$array[$i-6-1]}}
This implies that the 6th line above your “No alert email was sent.” is what you are looking for. Also have to substract 1 since the array is zero based. It is not pretty, however it works
As a side note, this does not work if you paste the code into a console window. The here-string becomes an one item array in the console, but not in ISE. Apparently the -split is unable to split on newline in the console.
Cheers
Tore