PowerShell:如何在递归数据搜索中去掉输出行

PowerShell:如何在递归数据搜索中去掉输出行,powershell,Powershell,我有100个.sql文件,我想检查字符串“Das ist ein Test”是否包含在此文件中 到目前为止,我只找到了Select-Stringcmdlet。但是,这只提供了在其中找到字符串的文件 下面是我的PowerhShell脚本: $path = "F:\Masterarbeit\Daten\" $search = "Das ist ein Test" Get-ChildItem $path -Filter *.sql -Recurse | Select-String -Pattern

我有100个.sql文件,我想检查字符串
“Das ist ein Test”
是否包含在此文件中

到目前为止,我只找到了
Select-String
cmdlet。但是,这只提供了在其中找到字符串的文件

下面是我的PowerhShell脚本:

$path = "F:\Masterarbeit\Daten\"
$search = "Das ist ein Test"

Get-ChildItem $path -Filter *.sql -Recurse | Select-String -Pattern $search -casesensitive | select FileName

exit
这是我得到的输出:


我现在如何更改代码,以便只获取不包含字符串的文件名?我还知道有一个名为
-NotMatch
的参数,但不幸的是,它只返回未找到字符串的所有行。

现在您正在检查每个文件的每一行。您要做的是检查每个文件(如果它包含字符串)


现在,您正在检查每个文件的每一行。您要做的是检查每个文件(如果它包含字符串)


我将使用
-not
操作符将
选择字符串
包装在
Where object
块中

Get-ChildItem $path -Filter *.sql -Recurse |
#Only keep files that don't return a match
Where-Object { -not (Select-String -Path $_.FullName -Pattern $search -casesensitive) } |
Select-Object Name

我将使用
-not
操作符将
选择字符串
包装在
Where object
块中

Get-ChildItem $path -Filter *.sql -Recurse |
#Only keep files that don't return a match
Where-Object { -not (Select-String -Path $_.FullName -Pattern $search -casesensitive) } |
Select-Object Name

啊,好的,谢谢你的提示,但现在我收到一条错误消息,路径找不到-->例如:
get Content:路径“C:\Windows\system32\Daten_1.sql”找不到,因为它不存在+$test=get Content$file |选择String$search
。我对错误消息有点困惑。显然$file本身并不能返回完整路径。我必须添加
.FullName
,它才能工作。啊,好的,谢谢你的提示,但是现在我收到一条错误消息,路径找不到-->例如:
get Content:path“C:\Windows\system32\Daten_1.sql”找不到,因为它不存在+$test=get Content$file |选择String$search
。我对错误消息有点困惑。显然$file本身并不能返回完整路径。我必须添加
.FullName
,它才能工作。