From c913a6bd508ead0e1c77ad25ab195ff8cf4205af Mon Sep 17 00:00:00 2001 From: Joshua Barnett Date: Fri, 31 Mar 2023 13:22:17 -0400 Subject: [PATCH 1/3] Use the correct HostVMAdapter when there are multiple associated with the specified switch. --- builder/hyperv/common/powershell/hyperv/hyperv.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/hyperv/common/powershell/hyperv/hyperv.go b/builder/hyperv/common/powershell/hyperv/hyperv.go index d114e00d..ed603d54 100644 --- a/builder/hyperv/common/powershell/hyperv/hyperv.go +++ b/builder/hyperv/common/powershell/hyperv/hyperv.go @@ -32,7 +32,7 @@ type scriptOptions struct { func GetHostAdapterIpAddressForSwitch(switchName string) (string, error) { var script = ` param([string]$switchName, [int]$addressIndex) -$HostVMAdapter = Hyper-V\Get-VMNetworkAdapter -ManagementOS -SwitchName $switchName | Select-Object -First 1 +$HostVMAdapter = Hyper-V\Get-VMNetworkAdapter -ManagementOS -SwitchName $switchName | Get-VMNetworkAdapterIsolation | Where-Object { $_.IsolationMode -eq "Vlan" } if ($HostVMAdapter){ $HostNetAdapter = Get-NetAdapter -IncludeHidden | Where-Object { $_.DeviceId -eq $HostVMAdapter.DeviceId } if ($HostNetAdapter){ From 7bbb80fbb9b342166c6a147a04512c705b3f185d Mon Sep 17 00:00:00 2001 From: Joshua Barnett Date: Fri, 31 Mar 2023 16:44:35 -0400 Subject: [PATCH 2/3] Update hyperv.go Return the HostVMAdapter through ParentAdapter property. --- builder/hyperv/common/powershell/hyperv/hyperv.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/hyperv/common/powershell/hyperv/hyperv.go b/builder/hyperv/common/powershell/hyperv/hyperv.go index ed603d54..cfb423eb 100644 --- a/builder/hyperv/common/powershell/hyperv/hyperv.go +++ b/builder/hyperv/common/powershell/hyperv/hyperv.go @@ -32,7 +32,7 @@ type scriptOptions struct { func GetHostAdapterIpAddressForSwitch(switchName string) (string, error) { var script = ` param([string]$switchName, [int]$addressIndex) -$HostVMAdapter = Hyper-V\Get-VMNetworkAdapter -ManagementOS -SwitchName $switchName | Get-VMNetworkAdapterIsolation | Where-Object { $_.IsolationMode -eq "Vlan" } +$HostVMAdapter = (Hyper-V\Get-VMNetworkAdapter -ManagementOS -SwitchName $switchName | Get-VMNetworkAdapterIsolation | Where-Object { $_.IsolationMode -eq "Vlan" }).ParentAdapter if ($HostVMAdapter){ $HostNetAdapter = Get-NetAdapter -IncludeHidden | Where-Object { $_.DeviceId -eq $HostVMAdapter.DeviceId } if ($HostNetAdapter){ From 4e0bffb3071f35ae29a9e50501d108f5730b31dc Mon Sep 17 00:00:00 2001 From: Joshua Barnett Date: Fri, 31 Mar 2023 18:21:20 -0400 Subject: [PATCH 3/3] Select correct adapter by filtering where IsolationMode is None. --- builder/hyperv/common/powershell/hyperv/hyperv.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/hyperv/common/powershell/hyperv/hyperv.go b/builder/hyperv/common/powershell/hyperv/hyperv.go index cfb423eb..79adee24 100644 --- a/builder/hyperv/common/powershell/hyperv/hyperv.go +++ b/builder/hyperv/common/powershell/hyperv/hyperv.go @@ -32,7 +32,7 @@ type scriptOptions struct { func GetHostAdapterIpAddressForSwitch(switchName string) (string, error) { var script = ` param([string]$switchName, [int]$addressIndex) -$HostVMAdapter = (Hyper-V\Get-VMNetworkAdapter -ManagementOS -SwitchName $switchName | Get-VMNetworkAdapterIsolation | Where-Object { $_.IsolationMode -eq "Vlan" }).ParentAdapter +$HostVMAdapter = (Hyper-V\Get-VMNetworkAdapter -ManagementOS -SwitchName $switchName | Get-VMNetworkAdapterIsolation | Where-Object { $_.IsolationMode -eq "None" }).ParentAdapter if ($HostVMAdapter){ $HostNetAdapter = Get-NetAdapter -IncludeHidden | Where-Object { $_.DeviceId -eq $HostVMAdapter.DeviceId } if ($HostNetAdapter){