Automation

 View Only
  • 1.  How to exclude the IPV6 address from a list

    Posted Feb 06, 2019 11:34 AM

    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



  • 2.  RE: How to exclude the IPV6 address from a list
    Best Answer

    Posted Feb 06, 2019 11:50 AM

    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



  • 3.  RE: How to exclude the IPV6 address from a list

    Posted Feb 06, 2019 12:30 PM

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

    Once again, you're a great help.



  • 4.  RE: How to exclude the IPV6 address from a list

    Posted Aug 25, 2022 07:32 PM

    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