trouble listing specific IP of VMs with multiple IP's assigned

can't figure out what i'm doing wrong using a query to list a specific IP of VMs that have more than one, any guidance would be appreciated


the below works fine for one VM (it has two IPs)

Get-VM -Name VM | Select Name , powerstate ,  @{N='IP';E={[string]::Join(',',$_.Guest.ipaddress -notmatch "10.100")}}

Name   PowerState IP
----   ---------- --
VM     PoweredOn


but not for a group of VMs

get-cluster "cluster" | Get-VM | Sort | Get-View -Property @("Name", "Config.Annotation", "Guest.GuestFullName", "Guest.IPAddress") | Select -Property Name, @{N="Running OS";E={$_.Guest.GuestFullName}},@{N='IP';E={[string]::Join(',',$_.Guest.ipaddress -notmatch "10.100")}}

Name    Running OS                                      IP
----    ----------                                      --
VM1     Microsoft Windows Server 2008 R2 (64-bit)       True
VM2     Microsoft Windows Server 2008 R2 (64-bit)       True




0 Kudos
2 Replies

You are using different properties for the two snippets.
The first one uses a .NET object and the Guest.IPAddress property produces an array of strings.

If you use the vSphere object (which you get through the Get-View cmdlet in the 2nd snippet), you don't want to use the Guest.IPAddress property, which is a single string.
But you want to use the IPAddress properties in the Guest.Net array.

Something like this for example

Get-VM -Name VM | 
Get-View -Property @("Name", "Config.Annotation", "Guest.GuestFullName", "Guest.Net") | 
Select Name , powerstate ,  @{N='IP';E={[string]::Join(',',$_.Guest.Net.IpAddress -notmatch "10.100")}}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference


thanks Luc, that fixed me right up!  brilliant as always

0 Kudos