Add Support for LINQ
Votes from Connect: 61
Original Date Submitted: 1/11/2011 12:54:36 PM
Handle: Joel -Jaykul- Bennett
Site Name: PowerShell
Feedback ID: 635454
Frequency: Always Happens
Regression: Yes, this happens in all previous versions
When LINQ is available, it can push queries into the native language of the underlying storage without requiring users to learn that query language. This transformation can speed up queries to perform hundreds times faster, and when the alternative is to ship large amounts of data over the wire to be filtered locally, thousands of times faster.
In many cases using LINQ can convert a script which ran so slow as to be infeasible into scripts that we can run every day, and in fact, can run whenever we like -- and it also drastically reduces CPU impact.
For a trivial example, see this post on Stack Overflow http://stackoverflow.com/questions/4559233/technique-for-selectively-formatting-data-in-a-powershell-pipeline-and-output-as where the switch to using LINQ (by embedded the LINQ into a C# function via Add-Type and calling it from PowerShell) provided 1000 times speedup. It's currently not possible to write that LINQ query at all in pure PowerShell, and the alternative (as it was written in the other answer on that StackOverflow question, using Where-Object) is extremely slow even on modest data sets.
The bottom line is that the Where-Object and Select-Object cmdlets are very slow, and using them to query databases, and other remote systems results in not only the slowdown of processing thousands of items in a Where-Object, but potentially sending them all over the wire as well.
Since LINQ to events is becoming available through the Rx project, it's more useful, and more important than ever, and we really need a way to write LINQ natively in PowerShell.
Product Studio item created by Connect Synchronizer due to creation of feedback ID 635454 (http://connect.microsoft.com/PowerShell/feedback/ViewFeedback.aspx?FeedbackID=635454).
Internal BugId: 2782
Robert Praetorius commented
Note that calling the static methods in System.Linq.Enumerable from PowerShell is not difficult (at least for fairly modern versions of PowerShell). The main thing you need to do is talk to PowerShell in a way that it understands what overload to select and what generic arguments to use. For example, while PowerShell gives up on [System.Linq.Enumerable]::Union((1,2,3),(2,3,4)), it has no trouble with [System.Linq.Enumerable]::Union([int](1,2,3),[int](2,3,4)). Things get a little trickier with predicates, but are still quite doable. I haven't messed with Expression trees and IQueryable in PowerShell, so I can't comment intelligently on that, but I suspect it's also doable.
All that said, native support for LINQ syntax in PowerShell would be a delightful thing to have.