Migrate Host and Guests from SS to VDS using Powercli 5.5

I have a pretty popular older post to migrate off of a VDS to a standard switch using some of the API calls, but this has now been made easier with Powercli 5.5. The addition and update of a few cmdlets around standard switch and VDS migrations are now here!

Requirements: Powercli 5.5

These are:




The script below will show how to move a single host and all of it’s guests to a VDS for a host with 2 physical uplinks.  It can be modified if you have more than 2 uplinks.  You will need to be sure to modify the commands to your environment like the line to migrate vmk0 and vmk1 make sure they line up with what you named your management and Vmotion port group!

In the next post, I will document how to go in the other direction to get off of the VDS to the Standard Switch!

Here is the script, feel free to use and distribute! This script assumes you already have a VDS setup with Virtual Machine portgroups with the same name and VLAN ID’s as on the standard switch already configured and setup. This allows the for loop in the script to loop through each interface and set the network label.

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

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

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

#Add to new DVSwitch and swing leg over
$VMhostObj | Get-VMHostNetworkAdapter -Physical -Name "vmnic1" | Remove-VirtualSwitchPhysicalNetworkAdapter -Confirm:$false
$VDSwitch = Get-VDSwitch $VDSwitch
$VDSwitch |  Add-VDSwitchVMHost -VMHost $VMHost -Confirm:$false

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

# 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-VDSwitchPhysicalNetworkAdapter -DistributedSwitch $VDSwitch -VirtualNicPortgroup "Management","Vmotion" -VMHostVirtualNic $vmk0,$vmk1 -VMHostPhysicalNic $vmhostadapter -Confirm:$false

# 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-VDPortGroup -Name $_.NetworkName -VDSwitch $VDSwitch) -Confirm:$false

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

$vmhostadapter = $VMhostObj | Get-VMHostNetworkAdapter -Physical -Name vmnic0
$VDSwitch | Add-VDSwitchPhysicalNetworkAdapter -VMHostNetworkAdapter $vmhostadapter -Confirm:$false

6 Responses to Migrate Host and Guests from SS to VDS using Powercli 5.5

  1. Pingback: Migrate Host and Guests VDS to SS using Powercli 5.5 | NutzandBolts - An IT Systems Engineer Experiences

  2. Bill says:

    Hi, can you walk me through:

    foreach($vm in $vmlist){
    Get-NetworkAdapter $vm | %{
    Write-Host “Setting adapter” $_.NetworkName on $vm
    $_ | Set-NetworkAdapter -PortGroup (Get-VDPortGroup -Name $_.NetworkName -VDSwitch $VDSwitch) -Confirm:$false

    I know it works, but I’d like to understand it better as I’m a newbie.

    • markdjones82 says:

      Hey Bill sorry for the late response. I’ve had a very hectic work schedule!

      Basically, you are passing the list of each VM. Then on each VM it is saying get the network adapters and for each of those (% is shorthand for foreach loop) It will then set the adapters to the VDS group of the same name as standard.

  3. Omar Muntslag says:

    great script !!

    i used the switching from standard switch to dvs part.
    could you tell me how i could change it back from dvs to std switch ?

    $vmlist = get-vmhost esx04.pimdomain | get-vm
    foreach($vm in $vmlist){
    Get-NetworkAdapter $vm | %{
    Write-Host “Setting adapter” $_.NetworkName on $vm
    $_ | Set-NetworkAdapter -PortGroup (Get-VDPortGroup -Name $_.NetworkName -VDSwitch dvSwitchHP) -Confirm:$false

  4. Omar Muntslag says:

    oops.. i see a second post 🙂

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: