Last week I demonstrated how you can easily leverage the new PowerCLI 5.5 VDS cmdlets to migrate from a VSS (Virtual Standard Switch) to a VDS (vSphere Distributed Switch). During the development of the script, I needed a way to easily jump back and fourth between VSS->VDS and VDS->VSS and I wanted to automate this so I did not have to use the UI to reset my environment.

I initially thought this was not possible after playing around with a couple of the cmdlets but thanks to Kamen, a PowerCLI Engineer who was able to provide me with the necessary information to create a reverse migration script going from VDS to VSS.

Here is what my lab environment looks like which includes three ESXi hosts connected to a VDS called "VDS-01" which is backed by 4 pNICSs. The VDS contains 3 VMkernel interfaces and here are their respective DVPortgroup names: Management Network, Storage Network and vMotion Network.

On each ESXi host, there is an already created VSS called "vSwitch0". If one is not created or if you decide to name it something differently, then you will need to modify the script. Here is a quick screenshot of what that looks like

The PowerCLI example script below uses the Add-VirtualSwitchPhysicalNetworkAdapter cmdlet which accepts a list of pNICs, VMkernel interfaces and the portgroups to migrate from VDS to VSS. The order in which the VMkernel and portgroups are specified is critically important as they will be assigned based on the provided ordering. The script also create the necessary portgroups on the VSS which of course can be modified based on your environment. Once the migration has been completed, it will then use the Remove-VDSwitchVMHost cmdlet to remove the ESXi hosts from the VDS.

Disclaimer: Please ensure you test this script in a development/test lab before using it in a production environment.

Here is a screenshot of the script executing:

13 thoughts on “Automate the reverse, migrating from vSphere Distributed Switch to Virtual Standard Switch using PowerCLI 5.5

  1. Hi,
    I ran the script in my environment, and the scripts fails when migrating the port group.
    The command “Add-VirtualSwitchPhysicalNetworkAdapter” fails with the error “An error occurred while communicating with the remote host”.
    Are you familiar with this error?
    Thank you.

    • I’ve seen this error in other situation, but it sounds like your host may be experiencing some networking issues, either during the migration or hostd itself is having some problems.

      • Hey William, I’m seeing the same issue on multiple hosts in multiple environments. I don’t think it likes the switch over with the vmk management interface. If I’m thinking of this correctly, if I were to step through this manually in the Web Client, what you’d be doing is trying to add physical adapters to the vSwitch0. However, being that the physical adapters are already in use on the DVS, they will not show up as available physical network adapters to add when attempting to on the vSwitch0… Does that make sense?

  2. Hi

    What do I need to modify to move dvs to vss and portgroup for VM network? All the VMs will need to change portgroup labels to the vss portgroups


    • I cannot get this to work. The Add-VirtualSwitchPhysicalNetworkAdapter part fails when attempting to do the mgmt vmk0. Vmotion works fine.

  3. Hi William, How can I add the vlan ids of the port groups such that they get migrated to standard switch.

    • I figured out I could add it during the creation of the portgroups

      Write-Host “`Creating” $vmotion_name “portrgroup on” $vss_name
      $vmotion_pg = New-VirtualPortGroup -VirtualSwitch $vss -Name $vmotion_name -VlanID 114

  4. Hi William,

    I would like to do the same using python.
    Can you please pint to the right method/proc for migrating the vmks using python ?
    I need it urgent

Thanks for the comment!