Ignore errors on neighbor lookup and validate result
This commit is contained in:
parent
d15ff38d5c
commit
9f08337ce1
|
@ -27,7 +27,8 @@ 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
|
||||||
|
if ($ip_address) {
|
||||||
$ip_address = $addr.IPAddress
|
$ip_address = $addr.IPAddress
|
||||||
if ($ip_address.Contains(".")) {
|
if ($ip_address.Contains(".")) {
|
||||||
$ip4_address = $ip_address
|
$ip4_address = $ip_address
|
||||||
|
@ -35,6 +36,7 @@ if (([string]::IsNullOrEmpty($ip4_address)) -And ([string]::IsNullOrEmpty($ip6_a
|
||||||
$ip6_address = $ip_address
|
$ip6_address = $ip_address
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (-Not ([string]::IsNullOrEmpty($ip4_address))) {
|
if (-Not ([string]::IsNullOrEmpty($ip4_address))) {
|
||||||
|
|
Loading…
Reference in New Issue