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,7 +27,8 @@ 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
$addr = Get-NetNeighbor -LinkLayerAddress $macaddress -ErrorAction SilentlyContinue | select IPAddress
if ($ip_address) {
$ip_address = $addr.IPAddress
if ($ip_address.Contains(".")) {
$ip4_address = $ip_address
@ -36,6 +37,7 @@ if (([string]::IsNullOrEmpty($ip4_address)) -And ([string]::IsNullOrEmpty($ip6_a
}
}
}
}
if (-Not ([string]::IsNullOrEmpty($ip4_address))) {
$guest_ipaddress = $ip4_address