Migrate ESXi host and guests from 1000v / VDS to Standard Switch using Powercli

*UPDATE I HAVE UPDATED THIS WITH THE NEW POWERCLI 5.5 cmdlets here:*
Migrate Host and Guests VDS to SS using Powercli 5.5

On occasion, there is a need to migrate an entire host or even cluster from the VDS to a standard switch. We happen to do this frequently for assorted operations like an upgrade or moving to another VDS. So, I wrote a script combining some of my previous posts to put it all together.

Below are the configuration and the steps we would follow for our environment.  You may need to tweak the scripts slightly depending on how many interfaces that you have.

Our Configuration:

1.  Hosts are on the 1000v

2.  We only have 2, 10 GB uplinks/vmnics.  These are Dell half height blades.

3. No standard switch currently configured, but Vswitch0 is present.

4.  Only 1 VMkernel portgroup for Vmotion and Management respectively.

5.  Portgroup names are labeled identically the same (required for the for loop to work properly.

Steps to migrate to the standard switch:
Read more of this post

Migrate VMkernel Ports from 1000v or VDS to Standard Switch using Powercli

*UPDATE I HAVE UPDATED THIS WITH THE NEW POWERCLI 5.5 cmdlets here:*
Migrate Host and Guests VDS to SS using Powercli 5.5

On occasion, we have a need to be able to remove an ESXi host from our distributed switch to a standard switch. In order to do this you can go through the GUI and choose “Migrate” adapters shown in the screen shot below. The command below assumes that you already have at least 1 physical adapter on both the VDS and Standard Switch. That part can be scripted out as well to move one interface over first, migrate vmkernel ports, and then the other interface.

In my case we need to get hosts from a 4.x Vcenter to a 5.x Vcenter along with all the guests. I will detail this migration to get guests/hosts and script used in a later posting located here.

migrate_networking

This requires multiple clicks and can be tedious if you have multiple hosts that need to be done.  Currently, there is no way that I know of to migrate VMkernel networking from DVS to SS in powercli.  You can go the other direction using the new DVS cmdlet Set-VMHostNetworkAdapter and the port group option.

I wrote a cmdlet to migrate vmkernel ports from DVS to standard. Here it is and the usage:

MigrateDVSwitch-Adapter -VMHost host -Interface vmk1 -NetworkName Vmotion -VirtualSwitch vSwitch -Vlan 77

function MigrateDVSwitch-Adapter{
        #Specify Parameters, VMhostname, VMkernel interface, Network Name, Vlan ID, Standard Switch nameparam (
        [Parameter(Mandatory=$true)][string]$VMHost,
        [Parameter(Mandatory=$true)][string]$Interface,
        [Parameter(Mandatory=$true)][string]$NetworkName,
        [Parameter(Mandatory=$true)][int]$Vlan,
        [Parameter(Mandatory=$true)][string]$VirtualSwitch)

        #Get esxi object
        $VMHostobj = Get-VMHost $VMHost
	#Get Network ID
	$networkid = $VMHostObj.ExtenSionData.Configmanager.NetworkSystem

        # ------- AddPortGroup to Standard Switch
	$portgrp = New-Object VMware.Vim.HostPortGroupSpec
	$portgrp.name = $NetworkName
	$portgrp.vlanId = $Vlan
	$portgrp.vswitchName = $VirtualSwitch
	$portgrp.policy = New-Object VMware.Vim.HostNetworkPolicy
	$_this = Get-View-Id $networkid
	$_this.AddPortGroup($portgrp)

        # ------- UpdateVirtualNic ----Migrates the virtual interface to the standard switch
	$nic = New-Object VMware.Vim.HostVirtualNicSpec
	$nic.portgroup =$NetworkName
	$_this = Get-View-Id $networkid
	$_this.UpdateVirtualNic($Interface, $nic)