我正在尝试创建一个 PowerShell 脚本来从大型日志文件中选择特定的行。使用Select-String
,我已将数据简化为多行字符串中我需要的行。现在,我想进一步对其进行处理,以仅以单个逗号分隔的字符串返回这些行中的 ID 号。
当前代码:
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"
}
当前返回以下字符串:
信息 | 为 197988 创建批次 | 2016 年 3 月 24 日凌晨 02:10 信息 | 为 202414 创建批次 | 2016 年 3 月 24 日凌晨 02:10 信息 | 为 173447 创建批次 | 2016 年 3 月 24 日凌晨 02:10
想要得到格式的输出:
197988、202414、173447