diff --git a/plugins/providers/hyperv/scripts/get_switches.ps1 b/plugins/providers/hyperv/scripts/get_switches.ps1 new file mode 100644 index 000000000..ab601468a --- /dev/null +++ b/plugins/providers/hyperv/scripts/get_switches.ps1 @@ -0,0 +1,8 @@ +# This will have a SwitchType property. As far as I know the values are: +# +# 0 - Private +# 1 - Internal +# +$Switches = @(Get-VMSwitch ` + | Select-Object Name,SwitchType,NetAdapterInterfaceDescription) +Write-Output $(ConvertTo-JSON $Switches) diff --git a/plugins/providers/hyperv/scripts/import_vm.ps1 b/plugins/providers/hyperv/scripts/import_vm.ps1 index c25fff6fc..d4eb11e08 100644 --- a/plugins/providers/hyperv/scripts/import_vm.ps1 +++ b/plugins/providers/hyperv/scripts/import_vm.ps1 @@ -2,7 +2,9 @@ Param( [Parameter(Mandatory=$true)] [string]$vm_xml_config, [Parameter(Mandatory=$true)] - [string]$vhdx_path + [string]$vhdx_path, + + [string]$switchname=$null ) # Include the following modules @@ -41,8 +43,10 @@ $MemoryMaximumBytes = ($memory.limit."#text" -as [int]) * 1MB $MemoryStartupBytes = ($memory.size."#text" -as [int]) * 1MB $MemoryMinimumBytes = ($memory.reservation."#text" -as [int]) * 1MB -# Get the name of the virtual switch -$switchname = (Select-Xml -xml $vmconfig -XPath "//AltSwitchName").node."#text" +if (!$switchname) { + # Get the name of the virtual switch + $switchname = (Select-Xml -xml $vmconfig -XPath "//AltSwitchName").node."#text" +} # Determine boot device Switch ((Select-Xml -xml $vmconfig -XPath "//boot").node.device0."#text") {