VMware Cloud Community
skhan22
Contributor
Contributor

Set-NetworkAdapter and Pipe "|" Characters in PortGroup Name

I'm getting an error when running the following PowerCLI command with Pipe "|" characters in PortGroup Name. DVPortGroup on DvSwitch were created and pushed down by Cisco ACI and all of the DVPortGroup Names have pipe in it.

PS C:\Set-NetworkAdapter -NetworkAdapter $myNetworkAdapter -Portgroup "XYZ|xyx-profile|xyz-001-epg" -Verbose

Set-NetworkAdapter : 11/1/2021 10:52:51 PM Set-NetworkAdapter The specified parameter 'Portgroup' expects a single value, but your name criteria 'XYZ|xyx-profile|xyz-001-epg' corresponds to multiple values.
At line:1 char:1
+ Set-NetworkAdapter -NetworkAdapter $myNetworkAdapter -Portgroup "ASU| ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidResult: (System.Collecti...dObjectInterop]:List`1) [Set-NetworkAdapter], VimException
+ FullyQualifiedErrorId : Core_ObnSelector_SelectObjectByNameCore_MoreResultsThanExpected,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.SetNetworkAdapter

Need to migrate 100s of VMs to new DVPortGroups. Any help would be greatly appreciated. 

Thanks, SK

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership

Looks like more than 1 portgroup corresponds to that name.
Check with



Get-VdPortgroup  -Name 'XYZ|xyx-profile|xyz-001-epg'


Also, try with single quotes.


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

Reply
0 Kudos
skhan22
Contributor
Contributor

You're correct. There are 3 PortGroups corresponding to the same name as seen below. The reason for that is there are 3 clusters in our VxRail env and each cluster has it's own DvSwitch. I'm guessing that I need to use DVSwitch argument somewhere in the Set-NetworkAdapter command to make it work. Am I correct in assuming that?

PS C:\> Get-VdPortgroup -Name "XYZ|xyz-profile|xyz-001-epg"

Name NumPorts PortBinding
---- -------- -----------
XYZ|xyz-profile|xyz-001-epg 0 Static
XYZ|xyz-profile|xyz-001-epg 8 Static
XYZ|xyz-profile|xyz-001-epg 8 Static

Reply
0 Kudos
LucD
Leadership
Leadership

Yes, provided these VDS have distinct names.
If they don't, you can use the VMHost parameter on the Get-VDSwitch cmdlet.


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

Reply
0 Kudos
skhan22
Contributor
Contributor

Hi LucD, thanks for your response. I ended up using the following example to make it work.

$vmname = "vm name"
$vdsname = "vdswitch"
$oldpg = "old_portgroup"
$newpg = "new portgroup"

# get the
$vdPortGroup = Get-VDPortGroup -VDSwitch (Get-VDSwitch -Name $vdsname) -Name $newpg;

#VM to migrate to new portgroup on VDS
Get-VM -Name $vmname | Get-NetworkAdapter | where { $_.NetworkName -eq $oldpg } | Set-NetworkAdapter -PortGroup $vdPortGroup -RunAsync;

Reply
0 Kudos