Sql server 如何选择多行字符串(包括空格),如果找到则返回true-PowerShell/SQL批处理

Sql server 如何选择多行字符串(包括空格),如果找到则返回true-PowerShell/SQL批处理,sql-server,powershell,batch-file,powershell-2.0,powershell-3.0,Sql Server,Powershell,Batch File,Powershell 2.0,Powershell 3.0,我使用select字符串验证在一行中找到的字符串,但是我需要PowerShell来识别多行字符串,以及满足所有三个条件(见下文) 需要选择的.log文件中的输出: Return Value ------------ 0 我想要一些东西来验证以下字符串值(所有这三个值都要满足才能返回true) 我已经试过了,但是这相当于一个过滤器 | Select-String -pattern "Return Value", "------------", " 0"

我使用select字符串验证在一行中找到的字符串,但是我需要PowerShell来识别多行字符串,以及满足所有三个条件(见下文)

需要选择的.log文件中的输出:

Return Value
------------
           0
我想要一些东西来验证以下字符串值(所有这三个值都要满足才能返回true)

我已经试过了,但是这相当于一个过滤器

| Select-String -pattern "Return Value", "------------", "           0"
资料来源:

您可以使用带有多行选项的regex

$a=
@'
返回值
------------
0
'@
$b=
@'
返回值
------------
1.
'@
[regex]::Match($a,'返回值\s*-----------\s*0',[System.Text.RegularExpressions.RegexOptions]::多行)。成功#true
[regex]::Match($b,'返回值\s*-----------\s*0',[System.Text.RegularExpressions.RegexOptions]::Multiline).成功#错误

如果您发布日志的示例,我可以根据您的需要调整脚本。

我已经成功地将您的代码合并到.bat文件逻辑中,它工作得非常好。非常感谢。不客气。请关闭答案(使用绿色复选框图像将其标记为已解决)
| Select-String -pattern "Return Value", "------------", "           0"