There’s a lot for help/support for migrating to distrubuted virtual switches, but not much for going the other way.   You might need to go the otherway if, for example, you want to migrate an ESX host from one vCenter to another.  There’s a lof of variance, but first step is often replicating the dvSwitch config into a standard vSwitch.

This small script helps with that….

#setup if you're running in ISE
Add-PSSnapin vmware.vimautomation.core
#Add-PSSnapin VMware.VimAutomation.Vds - from v6 modules no longer in snapin.  in modules..
$p = [Environment]::GetEnvironmentVariable("PSModulePath")
$p+=";C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Modules”
[Environment]::SetEnvironmentVariable("PSModulePath",$p)
import-module VMware.VimAutomation.Vds

#Connect to vCenter and the source dvSwitch
#Connect to target host amd the target vSwitch ( create if it doesn't exist, same MTU etc.)
#Loop though all the portgroups and recreate with same name, mtu, vlanid unless they already exist

$vc = Connect-VIServer (Read-Host "Enter the name of source vCenter Server")
$sourcevds = Get-VDSwitch -Name (Read-Host "Enter the name of the source Distributed Virtual Switch")
$vmhost = Get-VMHost -Name (Read-Host "Please enter the name of the host to create/clone standard switch")
$targetvs = (Read-Host "Enter name of target vSwitch")

 
$sourcevds | foreach {
   If (($vmhost |Get-VirtualSwitch -Name $targetvs -ErrorAction SilentlyContinue)-eq $null){
       Write-Host "Creating Virtual Switch $($targetvs)"
       $NewSwitch = $vmhost |New-VirtualSwitch -Name $targetvs -Mtu $_.Mtu
       
   } else {
     Write-Host "Virtual Switch $($targetvs) already exists"
   }
   $vSwitch = Get-VirtualSwitch -Name $targetvs
   Get-VDPortGroup -VDSwitch $_ |Foreach {
       #skip Trunks (DVUplinks)
       if ($_.VlanConfiguration.VlanType -eq "Trunk" ) {
         Write-Host "Skipping $($_.Name)"
         continue
       }
       If (($vswitch |Get-VirtualPortGroup -Name $_.Name -ErrorAction SilentlyContinue)-eq $null){
           Write-Host "Creating Portgroup $($_.Name) $($_.VlanConfiguration.VlanID)"
           $NewPortGroup = $vmhost |Get-VirtualSwitch -Name $vSwitch |New-VirtualPortGroup -Name $_.Name -VLanId $_.VlanConfiguration.VLanID
       } else {
         Write-Host "Portgroup $($_.Name) already exists"
       }
    }
}
dvSwitch to vSwitch migration

Leave a Reply

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