Hi there,
I have an issue with adding physical nic to a specific uplink port on the VDS
In powercli we have this example
>man Add-VDSwitchPhysicalNetworkAdapter -Examples
-------------- Example 1 --------------
C:\PS>$vmhostNetworkAdapter = Get-VMHost "MyVMHost" | Get-VMHostNetworkAdapter -Physical -Name vmnic2
Get-VDSwitch "MyVDSwitch" | Add-VDSwitchPhysicalNetworkAdapter -VMHostPhysicalNic $vmhostNetworkAdapter
-------------- Example 2 --------------
C:\PS>$myVMHost = Get-VMHost "MyVMHost"
$physicalNic = Get-VMHostNetworkAdapter -VMHost $myVMHost -Name "vmnic0"
$virtualNic = Get-VMHostNetworkAdapter -VMHost $myVMHost -Name "vmk0"
Get-VDSwitch -Name "MyVDSwitch" | Add-VDSwitchPhysicalNetworkAdapter -VMHostPhysicalNic $physicalNic -VMHostVirtualNic $virtualNic -VirtualNicPortgroup 'MyVDPortGroup'
In command Add-VDSwitchPhysicalNetworkAdapter there aren't any parameter for specific uplink port
But, I have 6 uplink ports on my VDS uplink portgroup.
And I want to add nic to a specific uplink port. For example uplink1
How I can do it?
Thanks in advance.
Have a look at my DvSwitch Scripting – Part 4 – NIC Teaming post.
The Add-dvSwHostpNic function in there shows how to add a pNIC to a free Uplink port, but it could easily be changed to add replace a pNIC on a specific Uplink.
Let me know if you need some sample code?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
To replace a pNic on a specific Uplink, you can do something like this.
In the script the existing vmnic1 is replaced by vmnic2.
Note that the script doesn't do any sanity checking, for example checking if the pNics are already in use or not.
$vdsName = 'vds1'
$oldPNic = 'vmnic1'
$newPNic = 'vmnic2'
$vds = Get-VDSwitch -Name $vdsName
foreach($esx in (Get-View -Id $vds.ExtensionData.Summary.HostMember)){
$vds = $esx.Config.Network.ProxySwitch | where{$_.DvsName -eq $vdsName}
$netSys = Get-View -Id $esx.ConfigManager.NetworkSYstem
$proxy = $netSys.NetworkInfo.ProxySwitch | where{$_.DvsName -eq $vdsName}
$spec = New-Object VMware.Vim.HostNetworkConfig
$newProxy = New-Object VMware.Vim.HostProxySwitchConfig
$newProxy.ChangeOperation = [VMware.Vim.HostConfigChangeOperation]::edit
$newProxy.Uuid = $proxy.DvsUuid
$proxySpec = New-Object VMware.Vim.HostProxySwitchSpec
$proxySpec.Backing = $proxy.Spec.Backing
$proxySpec.Backing | %{
$_.PnicSpec | %{
if($_.PnicDevice -eq $oldPNic){
$_.PnicDevice = $newPNic
}
}
}
$newProxy.Spec = $proxySpec
$spec.ProxySwitch += $newProxy
$netSys.UpdateNetworkConfig($spec,[VMware.Vim.HostConfigChangeMode]::modify)
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I am migrating my vmnics one at a time to the vDS using the following script:
foreach ($VMHost in $VMHosts) {
$vmhostNetworkAdapter0 = Get-VMHost $vmhost | Get-VMhostNetworkAdapter -Physical -Name vmnic0
$vds | Add-VDSwitchPhysicalNetworkAdapter -VMHostNetworkAdapter $vmhostNetworkAdapter0
foreach ($VMHost in $VMHosts) {
$vmhostNetworkAdapter4 = Get-VMHost $vmhost | Get-VMhostNetworkAdapter -Physical -Name vmnic4
$vds | Add-VDSwitchPhysicalNetworkAdapter -VMHostNetworkAdapter $vmhostNetworkAdapter4
Is there a way to map vmnic0 to dvUplink0 and vmnic4 to dvUplink4 during this process?
Have a look at Re: Assign vminc to Specific Uplink on VDS
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference