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
{{ message }}
Repository navigation
Select-String -SimpleMatch should be mutually exclusive with -AllMatches, but the combination is currently accepted and quietly ignored #11091
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-No ActivityIssue has had no activity for 6 months or moreWG-Cmdletsgeneral cmdlet issues
When you specify -SimpleMatch, the output objects' .Matches property isn't populated at all - the only information about the input string's content is the .Line property.
Since all matches per input object would only be available via .Matches, specifying -AllMatches in combination with -SimpleMatch is pointless and should be prevented.
My guess is that the -rare - instances of this pointless combination in existing code stem from a misconception of what -AllMatches does; users may mistakenly think that -AllMatches is necessary to find all matches in a file (which happens by default), whereas in reality it is used to find all matches on each line.
As an aside: The alternative would be to also capture literal matches with -SimpleMatch (both one by default, and all with -AllMatches), but (a) that would be a nontrivial enhancement and (b) is of less interest than with regexes; that said, it would still be of interest in two respects:
if you match literally, but case-INsensitively with -SimpleMatch, and are interested in the specific case variation of the matching parts of the input line.
Even with literal matching you may be interested in how many matches occurred per line.
Steps to reproduce
# Without `-SimpleMatch`: OK, because .Matches is populated
('foo,foo'|Select-String-Pattern foo -AllMatches).Matches.Count | Should -Be 2# With -SimpleMatch:# The matching parts of the input lines aren't captured at all, so -AllMatches makes no sense.# An error should be thrown, but currently isn't:
{ 'foo,foo'|Select-String-SimpleMatch foo -AllMatches } | Should -Throw
Expected behavior
Both tests should pass.
Actual behavior
The 2nd test fails:
Expected an exception, to be thrown, but no exception was thrown
changed the title [-]Select-String -SimpleMatch is mutually exclusive with -AllMatches, but is quietly ignored[/-][+]Select-String -SimpleMatch should be mutually exclusive with -AllMatches, but the combination is currently accepted and quietly ignored[/+]on Nov 16, 2019
Good point - since specifying the inapplicable switch has currently no effect whatsoever, current code that uses it - meaninglessly - could conceivably break.
Given this, my vote is to make the change, not least because users should know that the combination doesn't make sense, so that the code doesn't end up not doing what they think it does.
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commented on Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commented on Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-No ActivityIssue has had no activity for 6 months or moreWG-Cmdletsgeneral cmdlet issues
Activity
[-]Select-String -SimpleMatch is mutually exclusive with -AllMatches, but is quietly ignored[/-][+]Select-String -SimpleMatch should be mutually exclusive with -AllMatches, but the combination is currently accepted and quietly ignored[/+]iSazonov commentedon Nov 18, 2019
I prepared the fix but it is a breaking change if now we will throw in the case.
mklement0 commentedon Nov 18, 2019
Thanks, Ilya (@iSazonov).
Good point - since specifying the inapplicable switch has currently no effect whatsoever, current code that uses it - meaninglessly - could conceivably break.
My hunch is that we're talking about a Bucket 3: Unlikely Grey Area](https://github.com/PowerShell/PowerShell/blob/master/docs/dev-process/breaking-change-contract.md#bucket-3-unlikely-grey-area) change, however, given that
-SimpleMatchitself appears not to be used all that frequently.Searching for https://github.com/search?q=select-string++simplematch+allmatches&type=Code
brings up only 79 code matches (most of them duplicates, and most of them PowerShell documentation / source code), but I did find 4 instances of combining
-AllMatcheswith-SimpleMatch, across 3 repos:https://github.com/AditiTechnologies/Brewmaster.ElasticSearch
https://github.com/bmmcclint/ps_scripts
https://github.com/miwaniza/Autodesk_Vault_Programmers_Cookbook
Given this, my vote is to make the change, not least because users should know that the combination doesn't make sense, so that the code doesn't end up not doing what they think it does.
vexx32 commentedon Nov 18, 2019
Seems like a fairly sound analysis to me. If users are using switches in tandem that simply don't work that way, they should be notified of that fact.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 23, 2023
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.