pspacek
Contributor
Contributor

Set-NetworkAdapter Error when there are duplicate portgroup names across multiple vds

So I get the following error when trying to set the portgroup on a network adapter only when I select a portgroup that is on multiple vds.

Command:

Get-VM Server1 | Get-NetworkAdapter | Set-NetworkAdapter -Portgroup "HOST|M1_ANP|COMPUTE_NFS_EPG" -confirm:$false | Out-Null

 

Error:

Set-NetworkAdapter : 12/11/2020 9:59:13 PM Set-NetworkAdapter The specified parameter 'Portgroup' expects a single value, but your name criteria 'HOST|M1_ANP|COMPUTE_NFS_EPG' corresponds to
multiple values.
At line:1 char:44
+ ... rkAdapter | Set-NetworkAdapter -Portgroup "HOST|M1_ANP|COMPUTE_NFS_EP ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidResult: (System.Collecti...dObjectInterop]:List`1) [Set-NetworkAdapter], VimException
+ FullyQualifiedErrorId : Core_ObnSelector_SelectObjectByNameCore_MoreResultsThanExpected,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.SetNetworkAdapter

Set-NetworkAdapter : 12/11/2020 9:59:13 PM Set-NetworkAdapter Value cannot be found for the mandatory parameter Portgroup
At line:1 char:44
+ ... rkAdapter | Set-NetworkAdapter -Portgroup "HOST|M1_ANP|COMPUTE_NFS_EP ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Set-NetworkAdapter], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.SetNetworkAdapter

 

If I remove the duplicate portgroup on a completely different VDS it works with no problem.  Is there a way to target the DVS Name and Port group when setting the adapter?  I can select it fine through vCenter but my automation script chokes on this command.  We have multiple VDS and a few portgroups that span them.

 

 

 

 

 

0 Kudos
4 Replies
scott28tt
VMware Employee
VMware Employee

@pspacek 

Moderator: Moved to PowerCLI Discussions


-------------------------------------------------------------------------------------------------------------------------------------------------------------

Although I am a VMware employee I contribute to VMware Communities voluntarily (ie. not in any official capacity)
VMware Training & Certification blog
0 Kudos
yosingh
Enthusiast
Enthusiast

Hi @pspacek 

You could try something like below.

Get-VDSwitch "vdsname" | Get-VM Server1 | Get-NetworkAdapter | Set-NetworkAdapter -Portgroup "HOST|M1_ANP|COMPUTE_NFS_EPG" -confirm:$false | Out-Null

LucD
Leadership
Leadership

If you are using OBN, you can have this kind of issue.
Make sure to select the specific portgroup you want.

$pg = Get-VDSwitch -Name MyvDs | Get-VDPortgroup -Name MyvDPg
Get-VM Server1 | Get-NetworkAdapter | Set-NetworkAdapter -Portgroup $pg -confirm:$false | Out-Null

 


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

pspacek
Contributor
Contributor

Thanks LucD, this worked perfect... This community is awesome..

0 Kudos