Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
パターンのディレクトリを検索しています。スイッチは -SimpleMatch -List です。ただし、ファイルのリストが返されます。最初のファイルとその最初の行のみを返すにはどうすればよいですか?
コマンドを使用してSelect-Object、最初の一致を返します。Get-ChildItemSelect-String でパス パラメータを指定できるため、使用する必要はありません。このSelect-StringコマンドMatchInfoは、一致する行とファイルの名前を含むオブジェクトを返します。
Select-Object
Get-ChildItem
Select-String
MatchInfo
$m = Select-String -Pattern get -Path *.ps1 -list -SimpleMatch | select-object -First 1 $m.Line $m.Path