Ignore errors on neighbor lookup and validate result
This commit is contained in:
parent
d15ff38d5c
commit
9f08337ce1
|
@ -27,12 +27,14 @@ if (([string]::IsNullOrEmpty($ip4_address)) -And ([string]::IsNullOrEmpty($ip6_a
|
||||||
$macaddresses = $vm | select -ExpandProperty NetworkAdapters | select MacAddress
|
$macaddresses = $vm | select -ExpandProperty NetworkAdapters | select MacAddress
|
||||||
foreach ($macaddr in $macaddresses) {
|
foreach ($macaddr in $macaddresses) {
|
||||||
$macaddress = $macaddr.MacAddress -replace '(.{2})(?!$)', '${1}-'
|
$macaddress = $macaddr.MacAddress -replace '(.{2})(?!$)', '${1}-'
|
||||||
$addr = Get-NetNeighbor -LinkLayerAddress $macaddress | select IPAddress
|
$addr = Get-NetNeighbor -LinkLayerAddress $macaddress -ErrorAction SilentlyContinue | select IPAddress
|
||||||
$ip_address = $addr.IPAddress
|
if ($ip_address) {
|
||||||
if ($ip_address.Contains(".")) {
|
$ip_address = $addr.IPAddress
|
||||||
$ip4_address = $ip_address
|
if ($ip_address.Contains(".")) {
|
||||||
} elseif ($ip_address.Contains(":")) {
|
$ip4_address = $ip_address
|
||||||
$ip6_address = $ip_address
|
} elseif ($ip_address.Contains(":")) {
|
||||||
|
$ip6_address = $ip_address
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue