Select-String to grep但只返回唯一的组

Tru*_*ill 10 regex powershell

我有一个包含很长行的文本文件.我需要来自每一行的一条信息,并且需要查看唯一值.我最初的想法是使用Select-String并指定带有捕获组的正则表达式.我看了几个其他的帖子,但都没有用.这是快速而肮脏的C#等价物:

var text = File.ReadAllText(@"path\File.txt");
var r = new Regex("Path=\"(.*?)\"");
var matches = r.Matches(text);

var h = new HashSet<string>();

foreach(Match match in matches)
{
    h.Add(match.Groups[1].Value);
}

foreach (var s in h)
{
    Console.WriteLine(s);
}
Run Code Online (Sandbox Code Playgroud)

我怎么能在PowerShell中这样做?

更新:

测试答案,我意识到还有一个额外的要求.每个源代码行可以有多个匹配项.例:

Path="One" Path="Two"
Path="Two" Path="Three"

结果应该是:

One
Two
Three

mjo*_*nor 16

select-string -path <filepath> -pattern 'Path=\"(.*?)\"' -allmatches  |
  foreach-object {$_.matches} |
   foreach-object {$_.groups[1].value} |
    Select-Object -Unique
Run Code Online (Sandbox Code Playgroud)