VMware Cloud Community
Ludicrous09
Enthusiast
Enthusiast
Jump to solution

add a physical nic to virtual standard switch

I am trying to add a physical nic to a virtual standard switch.

the command i am trying is below.

Get-VirtualSwitch vSwitch0 | Add-VirtualSwitchPhysicalNetworkAdapter -VMHostPhysicalNic vmnic5

Add-VirtualSwitchPhysicalNetworkAdapter : Cannot bind parameter 'VMHostPhysicalNic'. Cannot convert the "vmnic5" value of type "System.String" to

type "VMware.VimAutomation.ViCore.Types.V1.Host.Networking.Nic.PhysicalNic".

At line:1 char:89

+ ... 0 | Add-VirtualSwitchPhysicalNetworkAdapter -VMHostPhysicalNic vmnic5

+                                                                    ~~~~~~

    + CategoryInfo          : InvalidArgument: (:) [Add-VirtualSwitchPhysicalNetworkAdapter], ParameterBindingException

    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VimAutomation.ViCore.Cmdlets.Commands.AddVirtualSwitchPhysicalNetworkAdapter

I can do it the old way but it complains it will be deprecated in a future release.

PS C:\WINDOWS\system32> Set-VirtualSwitch -VirtualSwitch vSwitch0 -Nic vmnic0,vmnic5

WARNING: Parameter 'Nic' is obsolete. This parameter is deprecated. Use Add-VirtualSwitchPhysicalNetworkAdapter instead.

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
freydaddy
VMware Employee
VMware Employee
Jump to solution

Ahh so if you're connected directly to the host itself, you can exclude the Get-VMHost cmdlet.

Get-VirtualSwitch vSwitch0 | Add-VirtualSwitchPhysicalNetworkAdapter -VMHostPhysicalNic (Get-VMHostNetworkAdapter -Physical -Name "vmnic5")

View solution in original post

0 Kudos
6 Replies
freydaddy
VMware Employee
VMware Employee
Jump to solution

Add-VirtualSwitchPhysicalNetworkAdapter is expecting an object which references vmnic5. In your example you've provided a string ("vmnic5"), which does not resolve out to a physical nic object.

You could specify that with something like this:

Get-VirtualSwitch vSwitch0 | Add-VirtualSwitchPhysicalNetworkAdapter -VMHostPhysicalNic (Get-VMHost "esxi1" | Get-VMHostNetworkAdapter -Physical -Name "vmnic5")

Edit: Added the -Physical switch to Get-VMHostNetworkAdapter

0 Kudos
Ludicrous09
Enthusiast
Enthusiast
Jump to solution

Maybe that is part of my problem.  I am using this as part of a script to provision a host, there is no host name set yet, and the host is not connected to vcenter.  I am connecting directly to the host IP and using this script to set it up.  So there is only one object to work with and it won't take the IP as "esx1"  .  Any other suggestions.

0 Kudos
freydaddy
VMware Employee
VMware Employee
Jump to solution

Ahh so if you're connected directly to the host itself, you can exclude the Get-VMHost cmdlet.

Get-VirtualSwitch vSwitch0 | Add-VirtualSwitchPhysicalNetworkAdapter -VMHostPhysicalNic (Get-VMHostNetworkAdapter -Physical -Name "vmnic5")

0 Kudos
knikolov
VMware Employee
VMware Employee
Jump to solution

Looks like it cannot find a physical NIC named vmnic5. Does Get-VMHost | Get-VMHostNetworkAdapter -Physical -Name "vmnic5" return a result? When connected directly to the host the proposed command should be changed like this:

Get-VirtualSwitch vSwitch0 | Add-VirtualSwitchPhysicalNetworkAdapter -VMHostPhysicalNic (Get-VMHost | Get-VMHostNetworkAdapter -Physical -Name "vmnic5")

0 Kudos
Ludicrous09
Enthusiast
Enthusiast
Jump to solution

You got me most of the way there.  Thanks Matt

Get-VirtualSwitch vSwitch0 | Add-VirtualSwitchPhysicalNetworkAdapter -VMHostPhysicalNic (Get-VMHostNetworkAdapter -Physical -Name "vmnic5")

Get-VirtualSwitch -Name vSwitch0 | Add-VirtualSwitchPhysicalNetworkAdapter -VMHostPhysicalNic (Get-VMHostNetworkAdapter -Physical -Name "vmnic5")

Got it done for me or Alternately you can do

Get-VirtualSwitch -Name vSwitch0 | Add-VirtualSwitchPhysicalNetworkAdapter -VMHostPhysicalNic (Get-VMhost | Get-VMHostNetworkAdapter -Physical -Name vmnic5)

Thanks (Kyle Ruddy)

0 Kudos
gajuambi
Enthusiast
Enthusiast
Jump to solution

Here is a powercli+esxcli way

$esxcli = get-vmhost | get-esxcli -v2

$esxcliset = $esxcli.network.vswitch.standard.add

$args = $esxcliset.CreateArgs()

$args.ports = 'vmnic2'

$args.vswitchname = 'vSwitch0'

$esxcliset.Invoke($args)

or try out

https://raw.githubusercontent.com/MrAmbiG/vmware/master/vTool/

---------------------- Gajendra D Ambi [pardon my chat lingo]
0 Kudos