Skip to content

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:


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

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

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

or this one-liner:

New-VMHostNetworkAdapter -VMHost "" -PortGroup "dvPortGroup vMotion VLAN 100" -VirtualSwitch "dvSwitch Lab" -IP -SubnetMask -VMotionEnabled:$true

And this is what happens:

New-VMHostNetworkAdapter :  The specified DV portgroup 'dvPortGroup vMotion VLAN 100' 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 "" -PortGroup "dvPortGroup vMotion VLAN 100" -VirtualSwitch "dvSwitch Lab" -IP -SubnetMask -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:



3 thoughts on “Special Characters in dvSwitch Port Groups and PowerCLI”

  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 Reply

Your email address will not be published. Required fields are marked *