VMware Cloud Community
PGinhoux
Enthusiast
Enthusiast
Jump to solution

How to exclude the IPV6 address from a list

Hi,

I'm using the current script from LucD, I found in another discussion :

Get-VM -PipelineVariable vm | where{$_.Guest.Nics.IpAddress} | Get-NetworkAdapter |


@{N='VM';E={$vm.Name}},Name, @{N='VMHost';E={$vm.VMHost.Name}}, @{N=”IP Address”;E={$nic = $_; ($vm.Guest.Nics | where{$_.Device.Name -eq $nic.Name}).IPAddress -join '|'}}, MacAddress | Format-table -Autosize

It works fine, but it shows the IPV6 address I would like to exclude :

VM                   Name                   VMHost                   IP Address                                       MacAddress      

--              ----              ------             ----------                           ----------      

test-vm         Network adapter 1 esx03.domain.local fe80::b0fe:ab09:6b6:10f9|192.168.1.1 00:50:56:80:58:21

Is it something possible ?

Thanks in advance for the help.

Regards

Patrick

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try like this

Get-VM -PipelineVariable vm | where{$_.Guest.Nics.IpAddress} | Get-NetworkAdapter |

Select @{N='VM';E={$vm.Name}},Name,

   @{N='VMHost';E={$vm.VMHost.Name}},

   @{N=”IP Address”;E={

     $nic = $_

     $ips = ($vm.Guest.Nics | where{$_.Device.Name -eq $nic.Name}).IPAddress

     ($ips | where{([ipaddress]$_).AddressFamily -eq 'InterNetwork'}) -join '|'}}, MacAddress |

Format-table -Autosize


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

View solution in original post

0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

Try like this

Get-VM -PipelineVariable vm | where{$_.Guest.Nics.IpAddress} | Get-NetworkAdapter |

Select @{N='VM';E={$vm.Name}},Name,

   @{N='VMHost';E={$vm.VMHost.Name}},

   @{N=”IP Address”;E={

     $nic = $_

     $ips = ($vm.Guest.Nics | where{$_.Device.Name -eq $nic.Name}).IPAddress

     ($ips | where{([ipaddress]$_).AddressFamily -eq 'InterNetwork'}) -join '|'}}, MacAddress |

Format-table -Autosize


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

0 Kudos
PGinhoux
Enthusiast
Enthusiast
Jump to solution

Greats! it works fine; the output doesn't show anymore the IPV6 addresses.

Once again, you're a great help.

0 Kudos
techAB
Contributor
Contributor
Jump to solution

This was super helpful for me. Thanks.

I modified it somewhat to give me a CSV with just the VM Name and IP Address.

Since some VMs have multiple IP addresses, I do a "Data, Text to Columns" in Excel to that CSV. That allows me to use the commas as delimiter to get the IP Addresses split up in separate columns. I couldn't figure out how do it with PowerCLI. I hope that makes sense.

------

Get-VM | Where-Object {$_.PowerState -eq "PoweredOn"} | Select Name, @{N="IP Address";E={@($_.guest.IPAddress | where{([ipaddress]$_).AddressFamily -eq 'InterNetwork'}) -join ', '}} | Sort-Object Name | Export-Csv c:\temp\VM_IP_addresses.csv -NoTypeInformation

0 Kudos