获取 Select-String 输出的子字符串的最佳方法是什么?

What is the best way to get a substring of Select-String output?

我 运行 Select-String 在一个包含以下行的文件中:

....
Association ID: uj8da-21
....

Select-String -Path "..path.." -Pattern "Association ID:" -SimpleMatch 给我文件、行号、单词 "Association ID:" 等。我想要的只是值。从 Select-String 命令执行此操作的最佳方法是什么?

如果我想在这一行之后提取一系列行怎么办(比如,另外10行)——-Context参数是否可以去?

使用匹配组。

$matchInfo = Select-String -Path "C:\temp\text.txt" -Pattern "Association ID: (.*)" 
$matchInfo.Matches.Groups[1].Value

上下文是要走的路。

$matchInfo = Select-String -Path "C:\temp\text.txt" -Pattern "Association ID: (.*)" -Context 0,10
$matchInfo.Matches.Groups[1].Value
$matchInfo.Context.PostContext