Merge pull request #8017 from marcinbojko/master
hyper-v fix when management interface is not part of virtual switch
This commit is contained in:
commit
9f041216ba
|
@ -32,10 +32,9 @@ type scriptOptions struct {
|
||||||
func GetHostAdapterIpAddressForSwitch(switchName string) (string, error) {
|
func GetHostAdapterIpAddressForSwitch(switchName string) (string, error) {
|
||||||
var script = `
|
var script = `
|
||||||
param([string]$switchName, [int]$addressIndex)
|
param([string]$switchName, [int]$addressIndex)
|
||||||
|
|
||||||
$HostVMAdapter = Hyper-V\Get-VMNetworkAdapter -ManagementOS -SwitchName $switchName
|
$HostVMAdapter = Hyper-V\Get-VMNetworkAdapter -ManagementOS -SwitchName $switchName
|
||||||
if ($HostVMAdapter){
|
if ($HostVMAdapter){
|
||||||
$HostNetAdapter = Get-NetAdapter | ?{ $_.DeviceId -eq $HostVMAdapter.DeviceId }
|
$HostNetAdapter = Get-NetAdapter | Where-Object { $_.DeviceId -eq $HostVMAdapter.DeviceId }
|
||||||
if ($HostNetAdapter){
|
if ($HostNetAdapter){
|
||||||
$HostNetAdapterIfIndex = @()
|
$HostNetAdapterIfIndex = @()
|
||||||
$HostNetAdapterIfIndex += $HostNetAdapter.ifIndex
|
$HostNetAdapterIfIndex += $HostNetAdapter.ifIndex
|
||||||
|
@ -45,7 +44,15 @@ if ($HostVMAdapter){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
$HostNetAdapterConfiguration=@(Get-NetIPAddress -CimSession $env:computername -AddressFamily IPv4 | Where-Object { ( $_.InterfaceAlias -notmatch 'Loopback' ) -and ( $_.SuffixOrigin -notmatch "Link" )})
|
||||||
|
if ($HostNetAdapterConfiguration) {
|
||||||
|
return @($HostNetAdapterConfiguration.IpAddress)[$addressIndex]
|
||||||
|
}
|
||||||
|
else {
|
||||||
return $false
|
return $false
|
||||||
|
}
|
||||||
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
var ps powershell.PowerShellCmd
|
var ps powershell.PowerShellCmd
|
||||||
|
|
Loading…
Reference in New Issue