Hi,
I have this created this function (inspired by something i found from @lucd - obviously), which basically allows me to assign a vmnic to a specific uplink on a distributed switch.
Running the function, the first time, it works as advertised and adds the vmnic to the correct Uplink Port on the correct distrubuted switch. However, when I run it a second time, to add a different vmnic to a different uplink port, this also works (e.g. attaches the vmnic to the correct uplink), however, it will remove the previous vmnic that was previously attached.
Any ideas what I could be doing wrong or what I am missing?
TIA
Function Set-VDSProperties {
<#
This function will configure vDS
#>
Param(
[parameter(Mandatory=$true)]
[String]
$uplinkName,
[parameter(Mandatory=$true)]
[String]
$server,
[parameter(Mandatory=$true)]
[String]
$vdswitch,
[parameter(Mandatory=$true)]
[String]
$vmnic
)
$esx = Get-VMHost -Name $Server #changed
$vds = Get-VDSwitch -Name $vdswitch -VMHost $esx
$uplinks = Get-VDPort -VDSwitch $vds -Uplink | Where-Object {$_.ProxyHost -like $Server} #changed
$netSys = Get-View -Id $esx.ExtensionData.ConfigManager.NetworkSystem
$config = New-Object VMware.Vim.HostNetworkConfig
$proxy = New-Object VMware.Vim.HostProxySwitchConfig
$proxy.Uuid = $vds.ExtensionData.Uuid
$proxy.ChangeOperation = [VMware.Vim.HostConfigChangeOperation]::edit
$proxy.Spec = New-Object VMware.Vim.HostProxySwitchSpec
$proxy.Spec.Backing = New-Object VMware.Vim.DistributedVirtualSwitchHostMemberPnicBacking
$pnic = New-Object VMware.Vim.DistributedVirtualSwitchHostMemberPnicSpec
$pnic.PnicDevice = $vmnic #changed
$pnic.UplinkPortKey = $uplinks | Where-Object{$_.Name -eq $uplinkName} | Select-Object -ExpandProperty Key
$proxy.Spec.Backing.PnicSpec += $pnic
$config.ProxySwitch += $proxy
$netSys.UpdateNetworkConfig($config,[VMware.Vim.HostConfigChangeMode]::modify)
}