VMware Cloud Community
jeremychivers
Contributor
Contributor

How can I add a Portgroup to a VM

I have been trying to add a portgroup to a VM via the PowerCLI.

The command I am using is

Get-VM -Name 1 | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName dvPortGroup3

and the error I get is as follows

Set-NetworkAdapter : 30/01/2013 10:48:22 Set-NetworkAdapter The specified DV portgroup 'dvPortGroup3' can not be used for vnic connection:
Invalid portgroup type.

I can add the portgroup to the VM via the VMware Client.

Any pointers?

Thanks in advance.

Jeremy

Tags (1)
0 Kudos
5 Replies
aravinds3107
Virtuoso
Virtuoso

I think you are trying to add VM port group which is on vDS which required a portkey parameter

Check the below article which will help to find the free ports

http://www.lucd.info/2012/02/14/dvswitch-scripting-part-12-find-free-ports/

http://communities.vmware.com/message/1987845

If you find this or any other answer useful please consider awarding points by marking the answer correct or helpful |Blog: http://aravindsivaraman.com/ | Twitter : ss_aravind
0 Kudos
jeremychivers
Contributor
Contributor

Thanks for the quick reply.

I just updated the command to as follows

Get-VM -Name 1 | Get-NetworkAdapter | Set-NetworkAdapter -DistributedSwitch dvSwitch2 -PortKey 10

The bold parts at the updates to the original code.

after running this I get the following error

Set-NetworkAdapter : 30/01/2013 11:37:03    Set-NetworkAdapter The specified port '10' does not exists or it's not available for vnic connection.

I have uploaded a screenshot showing that the vDS and portgroup, portkey exists.

Thanks

0 Kudos
LucD
Leadership
Leadership

Do you have the host where the VM is hosted, connected to the dvSwitch ?

In the "Connectee" column where you have "1", I see my connected ESXi


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

0 Kudos
jeremychivers
Contributor
Contributor

If i go into the VMware Client and go to Home > Inventory > Networking then select the port group or vDS it shows the host is connected.

Jeremy

0 Kudos
LucD
Leadership
Leadership

Strange, in my test environment I see this on the switch (after the connect of VM2 to port 10)

dvsw.png

I used the same cmdlets as you.

dvsw-connect-portkey.png

Which versions (vSPhere & PowerCLI) are you using ?

I used vSphere 5.1, dvSwitch 5.1 and PowerCLI 5.1 for my test.


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

0 Kudos