Automation

 View Only
Expand all | Collapse all

How to use Set-NetworkAdapter to assign distributed switch port?

  • 1.  How to use Set-NetworkAdapter to assign distributed switch port?

    Posted Jun 11, 2012 05:06 PM

    Set-NetworkAdapter : 6/11/2012 12:51:47 PM    Set-NetworkAdapter        The specified port '1405' does not exists or it's not available for vnic connection.

    I receive the above error message when trying to run:

    Get-VM SOMEGUEST | Get-NetworkAdapter | Set-NetworkAdapter -StartConnected $true -DistributedSwitch dvSwitch01 -PortKey 1405 -Confirm:$FALSE

    I have confirmed portkey 1405 exists and that it is not in use.  Please advise; thanks.

    Also tried this method but get the same result: http://www.vmware.com/support/developer/PowerCLI/PowerCLI501/html/Set-NetworkAdapter.html

    $distributedSwitch = Get-VirtualSwitch -Distributed -Name DistributedSwitch
    
    Get-VM VM | Get-NetworkAdapter | Set-NetworkAdapter -PortKey 1405 -DistributedSwitch $distributedSwitch


  • 2.  RE: How to use Set-NetworkAdapter to assign distributed switch port?

    Posted Jun 11, 2012 05:27 PM

    Is the portkey in the portgroup that you use on the VM ?



  • 3.  RE: How to use Set-NetworkAdapter to assign distributed switch port?

    Posted Jun 11, 2012 05:35 PM

    Yes, the portkey is within the portgroup's range.

    But anyways, how would the command even know which portgroup you wanted to use for the VM?



  • 4.  RE: How to use Set-NetworkAdapter to assign distributed switch port?

    Posted Jun 11, 2012 05:36 PM

    So the NIC is not connected to a portgroup ?



  • 5.  RE: How to use Set-NetworkAdapter to assign distributed switch port?

    Posted Jun 11, 2012 05:48 PM

    The NIC is currently assinged to a distributed switch port group.  I tried moving it to a standard switch portgroup but I receive the same error.  The free portkey function looks useful, but for now I just want to get the first step completed.  I have confirmed from vsphere client the portkey is free.



  • 6.  RE: How to use Set-NetworkAdapter to assign distributed switch port?

    Posted Jun 12, 2012 02:29 AM

    I noticed that when I show the properties of the port groups it shows "0" as the number of available ports; could that be the problem?  The port groups are using the default settings (128 ports - static binding).



  • 7.  RE: How to use Set-NetworkAdapter to assign distributed switch port?

    Posted Jun 12, 2012 06:04 AM

    That depends on the type of port binding you are using for that portgroup.

    If the binding is ephemeral, the number of ports is 0. And the portgroup allocates one port for each connected VM.

    And it looks indeed as if Set-NetworkAdapter doesn't work with ephemeral ports.



  • 8.  RE: How to use Set-NetworkAdapter to assign distributed switch port?

    Posted Jun 12, 2012 11:38 AM

    But as I mentioned the port groups are configured as static binding with the default number of ports, 128.  They are not set to ephemeral.  Not sure why the number of ports is showing as 0.



  • 9.  RE: How to use Set-NetworkAdapter to assign distributed switch port?

    Posted Jun 12, 2012 11:52 AM

    Just tried it from the vSphere client, and apparently it allows you to define a portgroup with 0 ports.

    But when you assign that portgroup to a NIC in a VM you get error (which sounds logical to me).

    I'm wondering why you would define a portgroup with 0 static ports ?

    As a placeholder perhaps ?

    Can't you assign ports to the portgroup ?



  • 10.  RE: How to use Set-NetworkAdapter to assign distributed switch port?

    Posted Jun 12, 2012 02:21 PM

    My portgroups have 128 ports (I used the default setting).  For example one of my port groups shows 10 guests connected, link up state, and they have connectivity.  And there are 118 unallocated ports in this portgroup.  If I run get-virtualportgroup -name "myportgrp" it returns numports = 0; I'm not sure why this is the case, but I did not define it as 0.



  • 11.  RE: How to use Set-NetworkAdapter to assign distributed switch port?

    Posted Jun 13, 2012 05:48 AM

    Does my function return any free ports on that port group ?

    It looks as if the NumPorts property has a problem :smileysad:



  • 12.  RE: How to use Set-NetworkAdapter to assign distributed switch port?

    Posted Jun 11, 2012 05:38 PM

    Btw, did you check the free port with my Get-dvPgFreePort function ?



  • 13.  RE: How to use Set-NetworkAdapter to assign distributed switch port?

    Posted Jun 12, 2012 08:02 PM

    A little off topic, but hoping it's related enough not to upset anyone..

    how can you use the set-networkadapter cmdlet to work with a standard vswitch?  Everything seems to be cusomized towards a vDS (makes sense usually, but this is a migration.. just need vswitches temporarly).

    When I don't specifiy a switch, it seems to default to the 1000v.

    thanks!



  • 14.  RE: How to use Set-NetworkAdapter to assign distributed switch port?

    Posted Jun 13, 2012 02:08 AM

    vDS has some customization because you must find a way to select a free port key (a method is not "built in") to use the main cmdlet.

    To work with standard switches you just need to specify the network name (the required parameters for the cmdlet are different when working with vDS):

    get-vm yourvm | | get-networkadapter | set-networkadapter -networkname yourstdprtgrp



  • 15.  RE: How to use Set-NetworkAdapter to assign distributed switch port?

    Posted Jun 13, 2012 02:39 AM

    I don't know why, but when I don't specify any switch, it operates on the 1000v.  Perhaps because mgmt is in it too?

    I've got a script working to change from the standard vswitch to the coresponding network in the 1000v working, but not the other way around.



  • 16.  RE: How to use Set-NetworkAdapter to assign distributed switch port?

    Posted Jun 13, 2012 02:52 AM

    Use the type switch; for example Set-NetworkAdapter -type e1000.