VMware Cloud Community
kalex1114
Contributor
Contributor
Jump to solution

assign nsxt segment dvsportgroup to network adapter

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

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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


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

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

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


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

0 Kudos
kalex1114
Contributor
Contributor
Jump to solution

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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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


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

0 Kudos
kalex1114
Contributor
Contributor
Jump to solution

Worked perfectly , thank you

0 Kudos