vMotion - Command Help

    Hey guys,

I am using William Lam extended vMotion script:

I got the script to work properly after reading some forums on a piece that was erring out. However I am getting stuck on how to tell the script to move the VM into a dvs network. I currently can do Standard Switch to Standard Switch. Here is the error I am seeing, I am hoping someone has seen this or can provide help.

VERBOSE: 9/10/15 10:10:54 AM Wait-Task Finished execution Wait-Task : 9/10/15 10:10:55 AM    Wait-Task        The operation for the entity "vMotion-Test01" failed with the following message: "Currently connected network interface 'Network adapter 1' uses network 'DVSwitch: 21 7a3e 50 33 ff d5 53-d0 0e c1 dd b1 8c 5e c1', which is not accessible."At C:\Scripts\vMotion.ps1:166 char:10

Here is the script I use:



   This script demonstrates an xVC-vMotion where a live running Virtual Machine

   is live migrated between two vCenter Servers which are NOT part of the

   same vCenter SSO Domain which is only available using the vSphere 6.0 API


   File Name  : run-cool-xVC-vMotion.ps1

   Author     : William Lam - @lamw

   Version    : 1.0




   sourceVC, sourceVCUsername, sourceVCPassword,

   destVC, destVCUsername, destVCPassword, destVCThumbprint

   datastorename, clustername, vmhostname, vmnetworkname,



   Console output


   The hostname or IP Address of the source vCenter Server

.PARAMETER sourceVCUsername

   The username to connect to source vCenter Server

.PARAMETER sourceVCPassword

   The password to connect to source vCenter Server


   The hostname or IP Address of the destination vCenter Server

.PARAMETER destVCUsername

   The username to connect to the destination vCenter Server

.PARAMETER destVCPassword

   The password to connect to the destination vCenter Server

.PARAMETER destVCThumbprint

   The SSL Thumbprint (SHA1) of the destination vCenter Server (Certificate checking is enabled, ensure hostname/IP matches)

.PARAMETER datastorename

   The destination vSphere Datastore where the VM will be migrated to

.PARAMETER clustername

   The destination vSphere Cluster where the VM will be migrated to

.PARAMETER vmhostname

   The destination vSphere ESXi host where the VM will be migrated to

.PARAMETER vmnetworkname

   The destination vSphere VM Portgroup where the VM will be migrated to


   The name of the source VM to be migrated










































#$source = "LA"

#$vmname = "vMA"


## LA->NY

#if ( $source -eq "LA") {

#  $sourceVC = ""

#  $sourceVCUsername = "administrator@vghetto.local"

#  $sourceVCPassword = "VMware1!"

#  $destVC = ""

#  $destVCUsername = "administrator@vsphere.local"

#  $destVCpassword = "VMware1!"

#  $datastorename = "vesxi60-8-local-storage"

#  $clustername = "NY-Cluster"

#  $vmhostname = ""

#  $destVCThumbprint = "82:D0:CF:B5:CC:EA:FE:AE:03:BE:E9:4B:AC:A2:B0:AB:2F:E3:87:49"

#  $vmnetworkname = "NY-VM-Network"

#} else {

## NY->LA

#  $sourceVC = ""

#  $sourceVCUsername = "administrator@vsphere.local"

#  $sourceVCPassword = "VMware1!"

#  $destVC = ""

#  $destVCUsername = "administrator@vghetto.local"

#  $destVCpassword = "VMware1!"

#  $datastorename = "vesxi60-7-local-storage"

#  $clustername = "LA-Cluster"

#  $vmhostname = ""

#  $destVCThumbprint = "B8:46:B9:F3:6C:1D:97:8C:ED:A0:19:92:94:E6:1B:45:15:65:63:96"

#  $vmnetworkname = "LA-VM-Network"


# Connect to Source vCenter Server

$sourceVCConn = Connect-VIServer -Server $sourceVC -user $sourceVCUsername -password $sourceVCPassword

# Connect to Destination vCenter Server

$destVCConn = Connect-VIServer -Server $destVC -user $destVCUsername -password $destVCpassword

# Source VM to migrate

$vm = Get-View (Get-VM -Server $sourceVCConn -Name $vmname) -Property Config.Hardware.Device

# Dest Datastore to migrate VM to

$datastore = (Get-Datastore -Server $destVCConn -Name $datastorename)

# Dest Cluster to migrate VM to

$cluster = (Get-Cluster -Server $destVCConn -Name $clustername)

# Dest ESXi host to migrate VM to

$vmhost = (Get-VMHost -Server $destVCConn -Name $vmhostname)

# Find Ethernet Device on VM to change VM Networks

$devices = $vm.Config.Hardware.Device

foreach ($device in $devices) {

   if($device -is [VMware.Vim.VirtualEthernetCard]) {

      $vmNetworkAdapter = $device



# Relocate Spec for Migration

$spec = New-Object VMware.Vim.VirtualMachineRelocateSpec

$spec.datastore = $datastore.Id

$ = $vmhost.Id

$spec.pool = $cluster.ExtensionData.ResourcePool

# New Service Locator required for Destination vCenter Server when not part of same SSO Domain

$service = New-Object VMware.Vim.ServiceLocator

$credential = New-Object VMware.Vim.ServiceLocatorNamePassword

$credential.username = $destVCusername

$credential.password = $destVCpassword

$service.credential = $credential

$service.instanceUuid = $destVCConn.InstanceUuid.toUpper()

$service.sslThumbprint = $destVCThumbprint

$service.url = "https://$destVC"

$spec.service = $service

# Modify VM Network Adapter to new VM Netework (assumption 1 vNIC, but can easily be modified)

$spec.deviceChange = New-Object VMware.Vim.VirtualDeviceConfigSpec

$spec.deviceChange[0] = New-Object VMware.Vim.VirtualDeviceConfigSpec

$spec.deviceChange[0].Operation = "edit"

$spec.deviceChange[0].Device = $vmNetworkAdapter

$spec.deviceChange[0].Device.backing.deviceName = $vmnetworkname

Write-Host "`nMigrating $vmname from $sourceVC to $destVC ...`n"

# Issue Cross VC-vMotion

$task = $vm.RelocateVM_Task($spec,"defaultPriority")

$task1 = Get-Task -Id ("Task-$($task.value)")

$task1 | Wait-Task -Verbose

# Disconnect from Source/Destination VC

Disconnect-VIServer -Server $sourceVCConn -Confirm:$false

Disconnect-VIServer -Server $destVCConn -Confirm:$false

Thanks guys for your help!

Tags (2)
0 Kudos
2 Replies

As far as I can tell, the function in its current form will only vMotion VMs that are connected to VSS, not VDS

Blog:  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos

You are correct. In its current form all I can do is VSS. I am looking for a way to modify it to allow vDS to vDS. I have searched online for any examples of just a migration of vDS to vDS with no luck. Its the same network on both vcenters, however the name of the vDS changes.

Thank you for your time with this.

0 Kudos