-
Notifications
You must be signed in to change notification settings - Fork 7.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an -Until
script block parameter to Select-Object
#21610
Comments
I wonder if it would be more generally useful to have a |
@SteveL-MSFT It would definitely be more generally useful. However, there's already an open issue for that, and there doesn't seem to be will or time to design and implement that feature, and this might be a stepping stone that's easier to decide on and implement, and should be a useful addition on its own. As an aside, I'd preferably make the exception public instead of creating a |
@MatejKafka can you link to the other issue on this? I've queued this up for the WG-Cmdlets to discuss so a conclusion will be made |
@SteveL-MSFT, said issue is already linked to from the initial post: |
Summary of the new feature / enhancement
As a user, I want to stop processing input after encountering a specific value in the pipeline.
A simple example:
A more realistic example:
Since
StopUpstreamCommandsException
, which is internally used bySelect-Object
to implement its early-exit behavior is internal, I don't believe there's currently any way to implement this without reflecting PowerShell internals. Using something like... | % {if (...) {break}; $_}
may seem like an attractive option, but as documented, it terminates much more (the whole runspace) than a user would naively expect.A more general solution could be to make
StopUpstreamCommandsException
public, so that users can write their own cmdlets with support for early exit, which is one of the possible solutions for #3821. However, even if that gets implemented, I believe the-Until
parameter could still be valuable for simpler use cases.Proposed technical implementation details (optional)
Add an
-Until
script block parameter toSelect-Object
, probably in a new parameter set, run the passed script block for each pipeline item and throwStopUpstreamCommandsException
when the script block returns a truthy value.I can open a PR if the feature is accepted. (although I'd kinda appreciate if someone found time to review my other PRs first, nudge nudge wink wink :) )
The text was updated successfully, but these errors were encountered: