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
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:
If I am doing the opposite test I can avoid using a script block with Where-Object:
I would like to be able to also avoid using a script block when using -Not which would enable the following: