Skip to content

Request: Where-Object used without -Property works on "the object" #8357

@HumanEquivalentUnit

Description

@HumanEquivalentUnit

These don't work, but it would be nice if they did:

PS C:\> 'test.txt', '', 'example.xml' | where -match 'txt'
where-object : The specified operator requires both the -Property and -Value parameters.

PS C:\> 1..10 | ? -gt $x
?: The specified operator requires both the -Property and -Value parameters.

but integers and strings have no -Property way to access their values. Select-String helps for text, but outputs MatchInfo not String. And doesn't help for any of the operators except -match.

Used without -Property it could implicitly use $_ with whatever casting that implies, the same as if you'd written { $_ -operator 'value' } as the filterscript.

And then you could do:

PS C:\> 'test.txt', '', 'example.xml' | ? | foreach { .. }

and that would implicitly act like ? { $_ } which does a boolean cast on the object and passes true ones.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-No ActivityIssue has had no activity for 6 months or moreWG-Cmdlets-Corecmdlets in the Microsoft.PowerShell.Core module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions