VMware Cloud Community
Newbey
Contributor
Contributor

How to add a physical NIC to a distributed virtual switch w/ PowerCLI

Hello All,

I've been trying to write a PowerCLI script to get a ESXi host to connect to a dvSwitch. Using VMWare's VDS modules I've been able to connect the ESXi host to the dvSwitch, but I can't get the NIC to connect to the dvUplink. I've tried the Move-VdsVMHostNetworkAdapter command fro the VDS module, but I get the following error:

Move-VdsVMHostNetworkAdapter : Cannot bind parameter 'Vds'. Cannot convert the "vmnic1" value of type "VMware.VimAutomation.ViCore.Impl.V1.Host.Networking.Nic.PhysicalNicImpl
" to type "VMware.VimAutomation.VdsComponent.Types.V1.VdsVSphereDistributedSwitch".

I've looked at LucD's function Add-dvSwHost to add a Host to the dvSwitch, but I get the following error:

Method invocation failed because [VMware.VimAutomation.ViCore.Impl.V1.Host.Networking.DistributedSwitchImpl] doesn't contain a method named 'UpdateViewData'.
At E:\Scripts\Old\dvSwitch1.ps1:21 char:25
+ $dvSwitch.UpdateViewData <<<< ()
    + CategoryInfo          : InvalidOperation: (UpdateViewData:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

I've even downloaded Onyx, to see if I could figure this out, but Onyx won't play well. I get the following message whenever I try to launch the app:

Exception has been thrown by the target of an invocation

I've tried Onyx on XP, 2003 Server, and 2008 R2, and on all the systems I get teh same error.

It's been a bad week, so far Smiley Sad

Thanks in advance for any help

Reply
0 Kudos
5 Replies
LucD
Leadership
Leadership

Which vSphere version are you using ? 4.* or 5.* ?

And which PowerCLI version ? Do a

Get-PowerCLIVersion


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Newbey
Contributor
Contributor

Hi LucD,

Thanks for replying.

I'm running vSphere 5 U1

The PowerCLI version is: 5.0.1 Build 581491

I wanted to add a host to an existing dvSwitch, which I can do. But, I'm having a hard time adding the pNic to the dvUplink. My goal is to create a script that will configure the ESXi if it needs to be rebuilt. I've just recently cut over to dvSwitches so, I'd like to update the existing script to attach to the existing dvSwitches.

I've been trying to look at your scripts and I'm sorry but, I just can't see anything wrong with your functions (which you so generously share to the community, and I thank you for that).

I'd like to use Onyx, but I can't figure out why I can't get it to work either. I've tried an older version, and it gave me the same error.

Thanks, for any help!!

Reply
0 Kudos
LucD
Leadership
Leadership

How did you get the dvSwitch that you passed as a parameter to the Add-dvSwHost function ?

Did you use the object that is returned by the Get-dvSwitch function ?

This should be a VMwareDistributedVirtualSwitch object, not a DistributedSwitch object as returned by the Get-VirtualSwitch cmdlet.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Newbey
Contributor
Contributor

I am a complete idiot.

I was using your other function, when the host was already connected to the dvSwitch. Doh!

I found your other function to add the pnics to the dvSwitch. So, I used your function "Get-dvSwitch" to pass the dvSwitch to the "Add-dvSwHostpNic" function so it is a VMwareDistributedVirtualSwitch and not a Distributed switch.

My script using your functions works, it's just throwing an error as it loops through the connected hosts:

Cannot index into a null array.
At E:\Scripts\dvSwitch\AddHostpNics.ps1:54 char:36
+ $pnic.UplinkPortKey = $keysUplinks[ <<<< $i]
    + CategoryInfo          : InvalidOperation: (0:Int32) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

The loop is trying to connect existing hosts whose pNics are already connected to the dvSwitch. If I wait for the loop to complete, the pnics that I need connected get connected. I just have to figure out how to search for a predefined host to have the loop only connect that predefined host.

I've looked through the mob, but I can't figure out the exact object to use. Any idea on how I should do this?

Thank you for all work great scripts and help. You are so very kind.

Reply
0 Kudos
LucD
Leadership
Leadership

Could it be that there aren't any free Uplinks on the dvSwitch ?

How many Uplinks did you specify when you created the dvSwitch ?

If these Uplinks are already used you will first have to increase the number of uplinks (see the 1st script in Part 4).

Btw the Add-dvSwHostpNic function isn't trying to connect ESXi hosts to the dvSwitch, it tries to connect additional pnics to the dvSwitch for each connected ESXi host.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos