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.
Connect-VIServer -Server vcenter55-1.primp-industries.com -User *protected email* -Pass vmware</b></i> # ESXi hosts to migrate from VSS->VDS $vmhost_array = @("vesxi55-1.primp-industries.com","vesxi55-2.primp-industries.com","vesxi55-3.primp-industries.com") # VDS to migrate from $vds_name = "VDS-01" $vds = Get-VDSwitch -Name $vds_name # VSS to migrate to $vss_name = "vSwitch0" # Name of portgroups to create on VSS $mgmt_name = "Management Network" $storage_name = "Storage Network" $vmotion_name = "vMotion Network" foreach ($vmhost in $vmhost_array) { Write-Host "`nProcessing" $vmhost # pNICs to migrate to VSS Write-Host "Retrieving pNIC info for vmnic0,vmnic1,vmnic2,vmnic3" $vmnic0 = Get-VMHostNetworkAdapter -VMHost $vmhost -Name "vmnic0" $vmnic1 = Get-VMHostNetworkAdapter -VMHost $vmhost -Name "vmnic1" $vmnic2 = Get-VMHostNetworkAdapter -VMHost $vmhost -Name "vmnic2" $vmnic3 = Get-VMHostNetworkAdapter -VMHost $vmhost -Name "vmnic3" # Array of pNICs to migrate to VSS Write-Host "Creating pNIC array" $pnic_array = @($vmnic0,$vmnic1,$vmnic2,$vmnic3) # vSwitch to migrate to $vss = Get-VMHost -Name $vmhost | Get-VirtualSwitch -Name $vss_name # Create destination portgroups Write-Host "`Creating" $mgmt_name "portrgroup on" $vss_name $mgmt_pg = New-VirtualPortGroup -VirtualSwitch $vss -Name $mgmt_name Write-Host "`Creating" $storage_name "Network portrgroup on" $vss_name $storage_pg = New-VirtualPortGroup -VirtualSwitch $vss -Name $storage_name Write-Host "`Creating" $vmotion_name "portrgroup on" $vss_name $vmotion_pg = New-VirtualPortGroup -VirtualSwitch $vss -Name $vmotion_name # Array of portgroups to map VMkernel interfaces (order matters!) Write-Host "Creating portgroup array" $pg_array = @($mgmt_pg,$storage_pg,$vmotion_pg) # VMkernel interfaces to migrate to VSS Write-Host "`Retrieving VMkernel interface details for vmk0,vmk1,vmk2" $mgmt_vmk = Get-VMHostNetworkAdapter -VMHost $vmhost -Name "vmk0" $storage_vmk = Get-VMHostNetworkAdapter -VMHost $vmhost -Name "vmk1" $vmotion_vmk = Get-VMHostNetworkAdapter -VMHost $vmhost -Name "vmk2" # Array of VMkernel interfaces to migrate to VSS (order matters!) Write-Host "Creating VMkernel interface array" $vmk_array = @($mgmt_vmk,$storage_vmk,$vmotion_vmk) # Perform the migration Write-Host "Migrating from" $vds_name "to" $vss_name"`n" Add-VirtualSwitchPhysicalNetworkAdapter -VirtualSwitch $vss -VMHostPhysicalNic $pnic_array -VMHostVirtualNic $vmk_array -VirtualNicPortgroup $pg_array -Confirm:$false } Write-Host "`nRemoving" $vmhost_array "from" $vds_name $vds | Remove-VDSwitchVMHost -VMHost $vmhost_array -Confirm:$false <i><b>Disconnect-VIServer -Server $global:DefaultVIServers -Force -Confirm:$false
Here is a screenshot of the script executing: