Automation

 View Only
  • 1.  assign nsxt segment dvsportgroup to network adapter

    Posted Mar 10, 2023 02:36 PM

    Hello all.  We have a script that deploys vms and configures them from csv file.  our old environment was a single cluster in vcenter but new environment is multi cluster vcenter.  Issue i'm running into I think is that since dvsportgroups are in nsxt they are assigned to multiple clusters and when i list the vdsportgroup i get 2 results back.  Command I'm running is this:

    get-vm testvm01 |Get-NetworkAdapter -Name "Network adapter 1" | Set-NetworkAdapter -DistributedSwitch $myvds -Portgroup tst-vds01 Set-NetworkAdapter : Cannot bind parameter 'DistributedSwitch'. Cannot convert the "tst-vds01" value of type "VMware.VimAutomation.ViCore.Impl.V1.Host.Networking.DistributedPortGroupImpl" to type "VMware.VimAutomation.ViCore.Types.V1.Host.Networking.DistributedSwitch". At line:1 char:104 + ... ork adapter 1" | Set-NetworkAdapter -DistributedSwitch $myvds -Portgr ... + ~~~~~~ + CategoryInfo : InvalidArgument: (:) [Set-NetworkAdapter], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevic e.SetNetworkAdapter

    Any ideas on how to fix this?

     

    Thank you



  • 2.  RE: assign nsxt segment dvsportgroup to network adapter

    Posted Mar 10, 2023 02:46 PM

    Afaik the Set-NetworkAdapter parameterset ConnectToPortgroup does not have a DistributedSwitch parameter, only a Portgroup parameter.
    The ConnectToPortByKey does have a DistributedSwitch parameter but then the PortId is a required parameter.

    Also, what do you have in $myvds?
    The error seems to say you have VDPortgroup in there



  • 3.  RE: assign nsxt segment dvsportgroup to network adapter

    Posted Mar 10, 2023 02:57 PM

    I also tried this:Get-VM testvm01 | Get-NetworkAdapter | Set-NetworkAdapter -Portgroup tst-vds01 -Confirm:$false | Out-Null and it also didn't work as i suspect since its nsxt segment it gets returned twice because its in 2 clusters that are currently on vcenter.  I'm trying to figure out how to limit the scope of the vds portgroup to only single cluster or some other way

    Set-NetworkAdapter : 3/10/2023 10:02:23 AM Set-NetworkAdapter The specified parameter 'Portgroup' expects a single value, but your name criteria 'tst-vds01' corresponds to multiple values. At line:1 char:41 + ... rkAdapter | Set-NetworkAdapter -Portgroup tst-vds01 - ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidResult: (System.Collecti...dObjectInterop]:List`1) [Set-NetworkAdapter], VimExcep tion + FullyQualifiedErrorId : Core_ObnSelector_SelectObjectByNameCore_MoreResultsThanExpected,VMware.VimAutomation.ViC ore.Cmdlets.Commands.VirtualDevice.SetNetworkAdapter Set-NetworkAdapter : 3/10/2023 10:02:23 AM Set-NetworkAdapter Value cannot be found for the mandatory parameter Portgroup At line:1 char:41 + ... rkAdapter | Set-NetworkAdapter -Portgroup tst-vds01 - ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Set-NetworkAdapter], VimException + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice. SetNetworkAdapter

     

     

    $myvds

    Name Key VLanId PortBinding NumPorts ---- --- ------ ----------- -------- tst-vds01 dvportgroup-1188 Ephemeral 8

    tst-vds01



  • 4.  RE: assign nsxt segment dvsportgroup to network adapter
    Best Answer

    Posted Mar 10, 2023 03:07 PM

    Instead of retrieving the VDPortgroup via OBN, did you already try getting it this way?

    Get-Cluster cluster | Get-VMHost | Get-VDSwitch -Name YourVDS | Get-VDPortgroup -Name tst-vds01

    Store the returned object in a variable, and then use that variable on the Portgroup parameter



  • 5.  RE: assign nsxt segment dvsportgroup to network adapter

    Posted Mar 10, 2023 03:43 PM

    Worked perfectly , thank you