Special Characters in dvSwitch Port Groups and PowerCLI

Do you use special characters in Port Groups or dvSwitch names? Then you might have problems with Scripts, Host Profiles or PowerCLI. Of course, usage of special characters like (&/"%) was always a bad idea, but sometimes you want to have nice-looking objects, as you might assume that names are nonfunctional labels. Unfortunately there are some issues with PowerCLI. And even worse, it is inconsistent. This post shows up a workaround when using special characters in Port Groups.

First of all: Are there any documented limitations? I searched for "allowed/forbidden special characters" information and couldn't find any information about that. So i assume that there are no limitations.

I stumbled about an issue with the "/", slash or forward slash character in port group names when using PowerCLI to create vmk ports. Why do i have a slash in my port group name? Because it's a network, and networks usually have a subnet mask:

portgroup-with-prefix

To create a vmk Port Group for vMotion i use this PowerCLI script:

$esx = Get-VMHost 192.168.222.13
$vs = Get-VirtualSwitch -Name "dvSwitch Lab"
$pg = Get-VirtualPortGroup -Name "dvPortGroup vMotion VLAN 100 192.168.0.0/24"

New-VMHostNetworkAdapter -VMHost $esx -PortGroup $pg -VirtualSwitch $vs -IP 192.168.0.50 -SubnetMask 255.255.255.0 -VMotionEnabled:$true

or this one-liner:

New-VMHostNetworkAdapter -VMHost "192.168.222.13" -PortGroup "dvPortGroup vMotion VLAN 100 192.168.0.0/24" -VirtualSwitch "dvSwitch Lab" -IP 192.168.0.50 -SubnetMask 255.255.255.0 -VMotionEnabled:$true

And this is what happens:

New-VMHostNetworkAdapter :  The specified DV portgroup 'dvPortGroup vMotion VLAN 100 192.168.0.0/24' cannot be found on vDS 'dvSwitch Lab'.

What is the Problem?
The New-VMHostNetworkAdapter Cmdlet does not work with the "/" character. Confusing part is that Get-VirtualPortGroup does. So Get-VirtualPortGroup finds the object, passes it to New-VMHostNetworkAdapter which can't find the Port Group.

How to Workaround?
To get the PowerCLI script work you have to encode the special character. That means that you have to replace the "/" with "%2F":

New-VMHostNetworkAdapter -VMHost "192.168.222.13" -PortGroup "dvPortGroup vMotion VLAN 100 192.168.0.0%2F24" -VirtualSwitch "dvSwitch Lab" -IP 192.168.0.50 -SubnetMask 255.255.255.0 -VMotionEnabled:$true

With this small workaround the New-VMHostNetworkAdapter Cmdlet will find the Port Group and creates vmk port. Here are some common used ASCII special characters and how to encode them:

ASCII encoding
! %21
" %22
# %23
$ %24
% %25
& %26
' %27
( %28
) %29
* %2A
+ %2B
, %2C
- %2D
. %2E
/ %2F
: %3A
; %3B
< %3C
= %3D
> %3E
? %3F
@ %40
[ %5B
\ %5C
] %5D

 

  1. Thank you - I was having the exact same problem for the exact same reason. Appreciate the details and most importantly - the resolution!

  2. Appreciate the above chart just wanted to make a slight correction to the table listed, until I gave PowerCLI a lowercase character it did not recognize the encoding. Ex. %2F above should be %2f

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>