Ignore errors on neighbor lookup and validate result

This commit is contained in:
Chris Roberts 2018-04-30 17:39:27 -07:00
parent d15ff38d5c
commit 9f08337ce1
1 changed files with 8 additions and 6 deletions

View File

@ -27,12 +27,14 @@ if (([string]::IsNullOrEmpty($ip4_address)) -And ([string]::IsNullOrEmpty($ip6_a
$macaddresses = $vm | select -ExpandProperty NetworkAdapters | select MacAddress
foreach ($macaddr in $macaddresses) {
$macaddress = $macaddr.MacAddress -replace '(.{2})(?!$)', '${1}-'
$addr = Get-NetNeighbor -LinkLayerAddress $macaddress | select IPAddress
$ip_address = $addr.IPAddress
if ($ip_address.Contains(".")) {
$ip4_address = $ip_address
} elseif ($ip_address.Contains(":")) {
$ip6_address = $ip_address
$addr = Get-NetNeighbor -LinkLayerAddress $macaddress -ErrorAction SilentlyContinue | select IPAddress
if ($ip_address) {
$ip_address = $addr.IPAddress
if ($ip_address.Contains(".")) {
$ip4_address = $ip_address
} elseif ($ip_address.Contains(":")) {
$ip6_address = $ip_address
}
}
}
}