Skip to content

Add Where-Object -Not support #3529

@ChrisMagnuson

Description

@ChrisMagnuson

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

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-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions