Migrate Host and Guests VDS to SS using Powercli 5.5

Here is the follow up to my previous posting Migrate Host and Guests from SS to VDS using Powercli 5.5

Requirements for script: Host with 2 physical interfaces, VSwitch must already be setup with VM portgroups with the same names as you have on the VDS. If you have more than 2 physical nics you can modify the script below with the remove and add adapter commands for all your NICS. There are plenty of scripts out there to copy the VDS to Vswitch port groups if that task needs to be done.

The script below will allow you to migrate your host and guests back to Standard Switch! There was one issue I found with the Add-VirtualSwitchPhysicalNetworkAdapter cmdlet when migrating VMkernel ports. Instead of being able to name the portgroup as it migrates, it takes the default name of VMkernel and VMkernel2 for Management and Vmotion respectively. Be sure to also hardcode the Vlan ID in the Set-VirtualPortGroup rename cmdlet below for your tags.

So, after migrating them we run a separate command to have those Vmkernel ports renamed. You can modify the script to name them how you would like. I named them Management Network and VMotion.

The script will prompt you for the host you want to migrate, the VDswitch name you want to migrate off of, and the Vswitch you want to migrate to.

It will move 1 interface over with the 2 Vmkernel ports VMotion/Management, loop through all interfaces of the VM’s and set the portgroups to the matching standard switch groups, migrate 2nd interface, and remove from VDS.

$VMHost = Read-Host "Enter Hostname to Migrate"
$VDSwitch = Read-Host "Enter VDSwitch Name"
$VSwitch = Read-Host "Enter Standard VSwitch Name"

#Get VMhost object data
$VMHostobj = Get-VMHost $VMHost

#create vmlist
$vmlist = $VMHostobj | Get-VM

#Remove 1 uplink and migrate to standard
$VMhostObj | Get-VMHostNetworkAdapter -Physical -Name "vmnic1" | Remove-VDSwitchPhysicalNetworkAdapter -Confirm:$false
$VSwitch = $VMhostObj | Get-VirtualSwitch -Name $VSwitch

#Get physical adapter to move
$vmhostadapter = $VMhostObj | Get-VMHostNetworkAdapter -Physical -Name vmnic1 

# Get 

# Get Vmotion and Management Virtual Adaptesr
$vmk0 = Get-VMHostNetworkAdapter -vmhost $vmhostobj -name vmk0
$vmk1 = Get-VMHostNetworkAdapter -vmhost $vmhostobj -name vmk1

# Add 1 physical adapter 
Add-VirtualSwitchPhysicalNetworkAdapter -VirtualSwitch $VSwitch -VMHostVirtualNic $vmk0,$vmk1 -VMHostPhysicalNic $vmhostadapter -Confirm:$false

#Rename the VMkernel ports to Vmotion and Management
$VMhostObj | Get-VirtualPortGroup -Name "VMkernel" | Set-VirtualPortGroup -VLanId 20 -Name "Management Network"
$VMhostObj | Get-VirtualPortGroup -Name "VMkernel2" | Set-VirtualPortGroup -VLanId 10 -Name "VMotion"

# Loop through guests and set their networks.
foreach($vm in $vmlist){
    Get-NetworkAdapter $vm | %{
    Write-Host "Setting adapter" $_.NetworkName on $vm
    $_ | Set-NetworkAdapter -PortGroup (Get-VirtualPortGroup -VMhost  $VMHost -Standard -Name $_.NetworkName) -Confirm:$false

#Swing Second Physical Interface Over
$VMhostObj | Get-VMHostNetworkAdapter -Physical -Name "vmnic0" | Remove-VDSwitchPhysicalNetworkAdapter -Confirm:$false

$vmhostadapter = $VMhostObj | Get-VMHostNetworkAdapter -Physical -Name vmnic0
Add-VirtualSwitchPhysicalNetworkAdapter -VirtualSwitch $VSwitch -VMHostPhysicalNic $vmhostadapter -Confirm:$false

#Remove from VDS
Get-VDSwitch $VDSwitch | Remove-VDSwitchVMHost -VMHost $VMhostObj -Confirm:$false


7 Responses to Migrate Host and Guests VDS to SS using Powercli 5.5

  1. Pingback: Migrate ESXi host and guests from 1000v / VDS to Standard Switch using Powercli | NutzandBolts - An IT Systems Engineer Experiences

  2. Pingback: Migrate VMkernel Ports from 1000v or VDS to Standard Switch using Powercli | NutzandBolts - An IT Systems Engineer Experiences

  3. dave says:

    when i try to remove the management nic it bombs, due to communication lose. how did you get passed that? Did your VSS already have management ip configured?

    • markdjones82 says:

      It will swing one interface over and basically “straddle” both VDS and Vswitch, that should then allow the management interface to move over.

    • Jay says:

      This may be due to how your physical switch ports are set up. Specifically, if they’re port channeled and you’re using the “Route based on IP hash” load balancing setting in the dvSwitch, the management network may drop when you try to move it.

      The solution would be to remove the port-channel and set the load balancing on the dvSwitch to the default “Route based on the originating virtual port ID”. The migration should then work.

  4. dave says:

    Thanks for the quick reply. I figured it out. We are trunking vlans, so i just needed to add the vlan ID, and it works.

  5. Oliver R. says:

    Does your command work in your environment for vm’s with more then one NIC? For me it did not. A second “foreach” loop was needed to go over each individual NIC from the vm’s. But anyway, your blogpost help a lot! Thank you!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: