Powershell 获取内容|从resultset中选择字符串返回仅顶部的行

Powershell 获取内容|从resultset中选择字符串返回仅顶部的行,powershell,Powershell,仅从下面的命令获取顶行: $G = Get-Content $SourceFile | select-string -pattern $SearchKeyword2`** 上面的命令返回它在文档中找到的多个行号,我们要选择前1。。返回。如何对此应用筛选器以仅返回一个顶行。。就像我们在SQL Server中所做的那样使用选择对象-第一个1: $G = Get-Content $SourceFile | Select-String -Pattern $SearchKeyword2 | Selec

仅从下面的命令获取顶行:

$G = Get-Content $SourceFile | select-string -pattern $SearchKeyword2`** 

上面的命令返回它在文档中找到的多个行号,我们要选择前1。。返回。如何对此应用筛选器以仅返回一个顶行。。就像我们在SQL Server中所做的那样

使用
选择对象-第一个1

$G = Get-Content $SourceFile | Select-String -Pattern $SearchKeyword2 | Select-Object -First 1

使用
选择对象-第一个1

$G = Get-Content $SourceFile | Select-String -Pattern $SearchKeyword2 | Select-Object -First 1