Skip to content

Add Where-Object -Not support #3529

Description

I often have the need to filter for objects that do not have a property specified or who have a falsey value for a property by doing something like the following:

$Computers = [PSCustomObject]@{
    ComputerName = "SPC-1234"
    IPAddress = "192.168.0.1"
},
[PSCustomObject]@{
    ComputerName = "BGP-5678"
    IPAddress = ""
},
[PSCustomObject]@{
    ComputerName = "MGC-9101"
}

$Computers | 
Where {-not $_.IPAddress }
ComputerName IPAddress
------------ ---------
BGP-5678              
MGC-9101 

If I am doing the opposite test I can avoid using a script block with Where-Object:

$Computers |
Where IPAddress
ComputerName IPAddress  
------------ ---------  
SPC-1234     192.168.0.1

I would like to be able to also avoid using a script block when using -Not which would enable the following:

$Computers | 
where -not IPAddress

Activity

  1. added
    WG-Languageparser, language semantics
    Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassif
    on Apr 11, 2017
  2. BrucePay commented on Apr 11, 2017

    @BrucePay
    Collaborator

    This is an issue with the Where-Object cmdlet not the language itself.

  3. added
    Issue-Enhancementthe issue is more of a feature request than a bug
    Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributors
    on Apr 12, 2017
  4. iSazonov commented on Apr 12, 2017

    @iSazonov
    Collaborator

    Bruce Payette (@BrucePay) Thanks! Clear.
    We have related Issue #2658 Do we want to really do this?

    /cc Jason Shirk (@lzybkr)

  5. SimonWahlin commented on Mar 8, 2018

    @SimonWahlin
    Contributor

    I think I could add a -Not parameterset to Where-Object.

    I can't find any tests for Where-Object, where are those?

  6. powercode commented on Mar 8, 2018

    @powercode
    Collaborator

    I think it is a good idea.

  7. iSazonov commented on Mar 12, 2018

    @iSazonov
    Collaborator

    Simon Wåhlin (@SimonWahlin) I dont found Where-Object test.
    I think we should place it in test\powershell\Modules\Microsoft.PowerShell.Core folder.

  8. SimonWahlin commented on Mar 12, 2018

    @SimonWahlin
    Contributor

    Thanks, I'll try to come up with a set of tests and place them there.

  9. iSazonov commented on Mar 12, 2018

    @iSazonov
    Collaborator

    Simon Wåhlin (@SimonWahlin) Please use new Pester 4 syntax in tests.

  10. SimonWahlin commented on Mar 12, 2018

    @SimonWahlin
    Contributor

    Absolutely!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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 reclassifIssue-Enhancementthe issue is more of a feature request than a bugResolution-FixedThe issue is fixed.Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdletsgeneral cmdlet issues

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions