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
Try like this
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
Try like this
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
Greats! it works fine; the output doesn't show anymore the IPV6 addresses.
Once again, you're a great help.
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