I'm attempting to create a PowerShell script to pick particular lines from large log files. Using Select-String
, I've gotten the data down to just the rows I need in a multiline string. Now I'd like to further massage it to return only the ID numbers from those rows, in a single, comma-delimited string.
Current code:
if (Select-String $SearchFile -Pattern $SearchString -Quiet) {
Write-Host "Error message found"
$body += Select-String $SearchFile -Pattern $SearchString -Context 1,0 |
foreach {$_.Context.DisplayPreContext} | Out-String
Send-MailMessage (email_info_here) -Body $body
} else {
Write-Host "No errors found"
}
Currently returning the following string:
INFO | Creating Batch for 197988 | 03/24/2016 02:10 AM INFO | Creating Batch for 202414 | 03/24/2016 02:10 AM INFO | Creating Batch for 173447 | 03/24/2016 02:10 AM
Would like to get the output to the format:
197988, 202414, 173447