From b6195693c90f1c18758182399af71de49aed8b12 Mon Sep 17 00:00:00 2001 From: Spencer Walden Date: Tue, 5 Jan 2021 16:51:07 -0800 Subject: [PATCH] Updates NATNetwork gateway IP check to be more specific to avoid different adapters having an IP address collision. --- HyperV/hyperv-create-nat-switch.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/HyperV/hyperv-create-nat-switch.ps1 b/HyperV/hyperv-create-nat-switch.ps1 index bd6c0fa..e75e916 100644 --- a/HyperV/hyperv-create-nat-switch.ps1 +++ b/HyperV/hyperv-create-nat-switch.ps1 @@ -20,8 +20,7 @@ If ("$NATSwitchName" -in (Get-VMSwitch | Select-Object -ExpandProperty Name) -eq } # Check that our Hyper-V host has the proper gateway address for the NAT Network. -# TODO make sure that this is set for the proper NATSwitch -If ("$NATHostIP" -in (Get-NetIPAddress | Select-Object -ExpandProperty IPAddress) -eq $FALSE) { +If (@(Get-NetIPAddress | Where-Object {$_.IPAddress -eq "$NATHostIP" -and $_.InterfaceAlias -eq "$NATSwitchNameAlias"}).Count -eq 1) { "Registering new IP address $NATHostIP on Windows Hyper-V host..." New-NetIPAddress -IPAddress $NATHostIP -PrefixLength $NATNetPrefixLength -InterfaceAlias $NATSwitchNameAlias