You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Any/All-Object cmdlet should be better to apply to pipeline.
But powershell currently might not be able to implement it properly becaue early breka of process block always skips end block so the result of Any/All-Object won't be able received by next pipe(not sure if it's possible when written in C#), see: #27389
I suggest that the PowerShell way would not be a unary operator. If it was unary, the only thing it could do was lists of booleans. A more compelling PowerShell solution would be just like Linq, it would "all meet some condition" or "any meet the condition". Linq is the best way for in-memory structures, a pipeline-able cmdlet would be better for the more general PowerShell scenario, like Any-Object or All-Object. Eg do any or all of these records meet some criteria.
The existing containment operators (-contains, -in, -notcontains, -notin) already provide basic -any functionality, just with less flexibility.
So extending them is a potential alternative to adding new operators/cmdlets. First, by implementing the following, which would enable arbitrary predicates:
And secondly by adding a new All option (just like -split has optional arguments).
$list=$true,$false,$true# Test if any element is the boolean true.# Equals() avoids implicit conversions.$list-contains { $true.Equals($_) }
# True# Test if *all* elements are the boolean true.$list-contains { $true.Equals($_) },'All'# False# Using -in to test for any element that's > 1:
{ $_-gt1 } -in1,2,3# True# Using -in to test for *all* elements that are > 1:
{ $_-gt1 },'All'-in1,2,3# False
Adding a new option would be breaking change, but I think there's an argument it falls under bucket 3 and could therefore be acceptable. An array literal on the RHS of -contains or LHS of -in is likely to be very uncommon (though of course would need to be verified). Something like this would technically be broken:
$OFS='|'# RHS gets stringified to "a|b".'a|b','c|d'-contains'a','b'# True
Whereas the following will always return $false (tests for reference equality), so it's unlikely users rely on this currently:
The complexity of all depends on what the result of an empty list should be, or whether you won't have any empty lists
It seems to me that contains/notcontains/notin are more in line with trying to search for characters in strings rather than the set of operations offered by Linq which have direct mappings to SQL.
The theory is that you can use ForEach-Object to perform a script to get a boolean result from each record and pipe those through Join-Boolean to get the collective answer.
For large volumes of data, it is better to use System.Linq.Enumerable, whereas a foreach loop suffices for small ones. After all, LINQ does require some initialization time upon first use.
As variants:
$list1="a","b","c"$list2="d","c","e","f","b","b","b"$list1.foreach({ $all+=$_-in$list2 })
$all-ge$list1.Count# Duration 0.001 ms
[string[]] $list1="a","b","c"$list2="d","c","e","f","b","b","b"$dlg= [Func[string,bool]] { $args[0] -in$list2 }
$all= [Linq.Enumerable]::All($list1,$dlg)
$all# Duration 0.007 ms (The first use)
$list1="a","b","c"$list2="d","e","f","a"$list1.foreach({ $any+=$_-in$list2 })
[bool] $any# 0.001 ms
[string[]] $list1="a","b","c"$list2="d","e","f","a"$dlg= [Func[string,bool]] { $args[0] -in$list2 }
$any= [Linq.Enumerable]::Any($list1,$dlg)
$any# 0.003 ms (The second use)
If the $list operand is assumed to contain [bool] instances only, as in the initial post, there'd be no need for dedicated operators, as the following will do:
$list -contains $true - -any functionality
$list -notcontains $false - -all functionality
If the intent is to perform to-[bool] coercion on the elements of $list:
While LINQ methods are always an option, from PowerShell (a) you can only provide all-in-memory-already input and (b) their use requires .NET-specific knowledge and techniques that are from PowerShell-idiomatic.
Previous issues have asked for more sophisticated functionality, based on using a script block ({ ... }) to determine the "truthiness" of each input element:
Mathias R. Jessen (@IISResetMe)'s PR #11086 , involving new -any and -all operators; while the PR was eventually closed by the author, the reason may have been merely prolonged neglect rather than any official opposition to the PR.
Previous issues have asked for more sophisticated functionality, based on using a script block ({ ... }) to determine the "truthiness" of each input element
There are many existing cmdlets that let you run script-blocks based on the input records, the missing component is the And aka All or Or aka Any at the end of the pipeline. That was the purpose of Join-Boolean. Eg
This isn't a this-or-that scenario, it is this and that.
The issue at hand, as well as the conceptually related ones mentioned, are operator-focused, which means they invariably operate on all-in-memory-up-front input. The trade-off is: processing speed vs. memory consumption.
Streaming solutions (in a PowerShell sense) are always also called for. Thus, they should be the focus of a separate proposal, say for a script block-focused Test-Object cmdlet with -All and -Any switches.
Activity
x5i4k4 commentedon Sep 25, 2026
Any/All-Objectcmdlet should be better to apply to pipeline.But powershell currently might not be able to implement it properly becaue early breka of
processblock always skipsendblock so the result ofAny/All-Objectwon't be able received by next pipe(not sure if it's possible when written in C#), see: #27389rhubarb-geek-nz commentedon Sep 25, 2026
It can be done directly with Linq
results in
rhubarb-geek-nz commentedon Sep 25, 2026
I suggest that the PowerShell way would not be a unary operator. If it was unary, the only thing it could do was lists of booleans. A more compelling PowerShell solution would be just like Linq, it would "all meet some condition" or "any meet the condition". Linq is the best way for in-memory structures, a pipeline-able cmdlet would be better for the more general PowerShell scenario, like Any-Object or All-Object. Eg do any or all of these records meet some criteria.
surfingoldelephant commentedon Sep 25, 2026
The existing containment operators (
-contains,-in,-notcontains,-notin) already provide basic-anyfunctionality, just with less flexibility.So extending them is a potential alternative to adding new operators/cmdlets. First, by implementing the following, which would enable arbitrary predicates:
And secondly by adding a new
Alloption (just like-splithas optional arguments).Adding a new option would be breaking change, but I think there's an argument it falls under bucket 3 and could therefore be acceptable. An array literal on the RHS of
-containsor LHS of-inis likely to be very uncommon (though of course would need to be verified). Something like this would technically be broken:Whereas the following will always return
$false(tests for reference equality), so it's unlikely users rely on this currently:rhubarb-geek-nz commentedon Sep 25, 2026
Going with the boolean rule of break-the-line-and-change-the-sign
Any is
All is
The complexity of all depends on what the result of an empty list should be, or whether you won't have any empty lists
It seems to me that contains/notcontains/notin are more in line with trying to search for characters in strings rather than the set of operations offered by Linq which have direct mappings to SQL.
trackd commentedon Sep 25, 2026
While I agree it would be a nice addition it has already been tried
#11068
rhubarb-geek-nz commentedon Sep 27, 2026
Taking the PSGallery route and noting that Any and All are not PowerShell verbs, however Join is the verb for combining data.
As part of rhubarb-geek-nz.Joinery I have added
Join-BooleanThe theory is that you can use ForEach-Object to perform a script to get a boolean result from each record and pipe those through
Join-Booleanto get the collective answer.237dmitry commentedon Sep 27, 2026
For large volumes of data, it is better to use
System.Linq.Enumerable, whereas aforeachloop suffices for small ones. After all, LINQ does require some initialization time upon first use.As variants:
mklement0 commentedon Sep 28, 2026
Let me attempt a summary:
If the
$listoperand is assumed to contain[bool]instances only, as in the initial post, there'd be no need for dedicated operators, as the following will do:$list -contains $true--anyfunctionality$list -notcontains $false--allfunctionalityIf the intent is to perform to-
[bool]coercion on the elements of$list:([bool[]] $list) -contains $true--anyfunctionality([bool[]] $list) -notcontains $false--allfunctionalityWhile LINQ methods are always an option, from PowerShell (a) you can only provide all-in-memory-already input and (b) their use requires .NET-specific knowledge and techniques that are from PowerShell-idiomatic.
Previous issues have asked for more sophisticated functionality, based on using a script block (
{ ... }) to determine the "truthiness" of each input element:Mathias R. Jessen (@IISResetMe)'s PR #11086 , involving new
-anyand-alloperators; while the PR was eventually closed by the author, the reason may have been merely prolonged neglect rather than any official opposition to the PR.surfingoldelephant's still-open proposal, Add script block support to containment operators #24748, is conceptually similar, but builds on the existing
-containsand-inoperators (and their negations) instead of aiming to introduce new operators.rhubarb-geek-nz commentedon Sep 28, 2026
There are many existing cmdlets that let you run script-blocks based on the input records, the missing component is the And aka All or Or aka Any at the end of the pipeline. That was the purpose of Join-Boolean. Eg
mklement0 commentedon Sep 28, 2026
This isn't a this-or-that scenario, it is this and that.
The issue at hand, as well as the conceptually related ones mentioned, are operator-focused, which means they invariably operate on all-in-memory-up-front input. The trade-off is: processing speed vs. memory consumption.
Streaming solutions (in a PowerShell sense) are always also called for. Thus, they should be the focus of a separate proposal, say for a script block-focused
Test-Objectcmdlet with-Alland-Anyswitches.kilasuit commentedon Sep 30, 2026
Thanks for pointing this out Andree Renneus (@trackd)
Mathias R. Jessen (@IISResetMe) do you remember why you canned that PR & it's sibling pr #11060
To quote Bruce Payette (@bpayette)
I personally don't see why we can't look to add
-any,-all&.All{}.Any{}- other than it's just more to support & document.This is not likely to get properly discussed & agreed on anytime soon.
Just to set expectations.