powershellvmware-tools

As of PSCustomObject remove extra values


I have command:

Get-VM | Where-Object {$_.NetworkAdapters.NetworkName -eq 'VLAN180'} | Select-Object Name, {$_.Guest.IPAddress}

return the following data:

ss4.work   {10.8.0.6, fe80::dd2a:a7d4:7de0:e64d, fe80::fd66:1962:4009:501a, 192.168.180.18}

I need the ip value - 192.168.180.*, but the problem is that $_.Guest.IPAddress it PSCustomObject and I do not understand how to use it.


Solution

  • $_.Guest.IPAddress is an array of objects, possibly PSObjects, possibly IPAddress objects, but the point is that there are several IPs in there and you have to select the ones you want. You also have a one to many relationship (Name to IP) so you have to decide how you want that; I'll assume that you're assuming there will only be one IP that matches the criteria:

    Maybe something like:

    Get-VM | 
        Where-Object {
            $_.NetworkAdapters.NetworkName -eq 'VLAN180'
        } | 
        Select-Object Name, {$_.Guest.IPAddress.Where({$_.ToString() -like '192.168.180.*'})}