Select-String to grep but just return unique groups

Viewed 5579

I have a text file that contains very long lines. I need one piece of information from each line, and need to see the unique values. My original thought was to use Select-String and specify a regular expression with a capture group. I've looked at several other posts but none worked. Here's the quick-and-dirty C# equivalent:

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);
}

How can I do this in PowerShell?

UPDATE:

Testing the answers, I realized there's an additional requirement. There can be multiple matches per source line. Example:

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

Results should be:

One
Two
Three
3 Answers
Related