PowerShell's equivalent of LINQ All, or how can I verify all the items in the collection are equal to specific value?

I have a collection of items, which I build from a regex match, like this:

$collection = $input | foreach {
    if ($_ -match $regex) {$matches} else { return }
} | 
  Select-Object –Property @{name='command'; expression={$_.command} },
                          @{name='id';      expression={$_.id} }

(sorry if that's not the best way to do this, I'm learning PowerShell :))

What I'd like to do is to make sure all the command properties in this $collection are equal to the same command, e.g. "myCommand", how can I do that?

ff this were C#, I'd probably do something like:

if (collection.All(item => item.Key == "myCommand")) { ... }

What's the idiomatic way to do this in PowerShell?

Answers


I was pointed to this LINQ Module for PowerShell, which allowed me to do simply:

$collection | Linq-All { $_.command -eq "myCommand" }

Which is just what I needed! More examples here.


Need Your Help

How to construct a class in a new thread?

c# multithreading .net-4.0 console

How to construct a class in a new thread? I have a static class called Server and a non-static class called ClientHandler. I would like to run the constructor of a new ClientHandler instance in a new

failed to looping dataset in jfreechart

list loops jfreechart

It is possible to create a loop dataset in jfreechart ?. I have a List that contains data.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.