Filtering output of get-netipconfiguration

hello
i am trying to lean powershell and here is my question
when is use

get-netipconfiguration | select-Object -Property ipv4address

it is show me

IPv4Address

{10.255.254.2}
{169.254.21.3}
{192.168.1.5}
{169.254.151.52}
{172.18.12.116}
{169.254.91.185}
{169.254.171.21}

but when i try

get-netipconfiguration | Where-Object -Property ipv4address -like *10*

there is no out put.
what is the problem ?

photo:

I think it’s because the IPV4 address property has multiple properties underneath it, however the way it’s displayed for output is only the IP address

So each ‘object’ has a IPV4 property, and that property has other properties, and your code is trying to see where the ipv4address property is like 10, and its not matching because you’re actually looking for a sub-property that is essentially being displayed to you when you run the command.

Take a look at a single object and actually look at the IPV4 property and i think it’ll expand out to much more data than just an address.

As for a fix, you can probably do something like this:

Get-NetIPConfiguration | Where-Object {$_.ipv4address.ipaddress -like '*10*'}

This basically just accesses the part you actually want to filter on, the IPaddress ‘sub-property’ and should return the entire objects in scope of that filter.

@dotnVo
your suggested command works.
i thought that with GET-MEMBER i will achieve to my response. the output of get-member did not show any sub-property. how can i find out that some property has sub-property ?

in the output of the command the filed name is ipv4address and i do not recognize it is IPv4address.ipaddress.
i get confused for future how do i find out which property has sub-property ? :frowning:

Sorry on mobile atm. Run get-member on the actual property and it’ll show the additional properties. The behavior you’re seeing is common in PowerShell. You can also simply access the properties using the dot (.). Basically set the output equal to a variable then access the property in question by doing $var.propertyname

Please do not post images of code or console output. Instead post the plain text and format it as code. :point_up:t3:

Thanks in advance. :+1:t3:

1 Like

Another clue is the definition. You can see the types: bool, int, string, and then ciminstance. That’s another clue it’s an object. But like Don said, it’s extremely common to save something to a variable and inspect it in many ways.

$netipconf = Get-NetIPConfiguration

$netipconf | Get-Member
$netipconf | Format-List *

$netipconf | Foreach-Object ipv4address
$netipconf | Foreach-Object ipv4address | Get-Member
2 Likes