Home > Blogs > VMware PowerCLI Blog

Spotlight on the Move-VM Cmdlet including PowerCLI 6.5 Enhancements

VMware PowerCLI 6.5’s release introduced a lot of new cmdlets and improvements to existing cmdlets. One of my favorite improved cmdlets has to be Move-VM. Move-VM was already a very versatile cmdlet before this new release. It could be used to move a VM between hosts, datastores, resource pools, clusters, to new folders, to a vApp, and so forth. Now, with PowerCLI 6.5 R1, Move-VM can move VMs between vCenters! We can even take that a step further, Move-VM can move VMs to vCenters which are not linked together by SSO domain. That’s something that cannot be done by the web client!

Let’s start by taking a look at the newest addition to the cmdlet, migrating VMs between vCenters.

Cross vCenter vMotion

Cross vCenter vMotion was introduced with vSphere 6.0. It’s proved to be a great feature that opens up new options in flexibly managing a vSphere environment. One of the limitations in using cross vCenter vMotion by way of the Web Client is that it can’t migrate VMs between SSO domains. This is where the usage of PowerCLI is hugely beneficial because PowerCLI allows users to fill that gap. The key to PowerCLI being able to overcome that limitation is due to its ability to connect to multiple vCenter servers at the same time.

In order to perform a cross vCenter vMotion, there are a couple parameters that are needed:

  • Active Connection to both Source and Destination vCenters
  • Source vCenter
    • VM
    • VM’s Network Adapter/s
  • Destination vCenter
    • Destination ESXi Host
    • Destination Datastore
    • Destination PortGroup/s

Here’s some example code on how that can be accomplished:

I also want to filling in a couple informative gaps in the above code:

  • Due to the cross vCenter vMotion functionality being added in as part of vSphere 6.0, it can only be performed against vCenter servers of 6.0 and newer.
  • The destination parameter only accepts an individual ESXi host. A workaround could look like the following code:
  • The datastore parameter only accepts an individual datastore. A workaround could look like the following code:

Multiple NIC VM vMotion

If you look at the example code above, specifically at the network pieces, you’ll notice that it only focuses on moving a VM with a single NIC. However, both the NetworkAdapter and PortGroup parameters accept arrays. This means that you can pass multiple objects to those parameters.

One key thing to note is that the first item in each array will be referenced together, then the second items will be referenced together, and so on and so forth. If there are multiple network adapters and only one portgroup specified, the network adapters will all be assigned to the same portgroup. If there is only a single network adapter and multiple portgroups specified, the command will error out.

Here’s an example of doing a Cross vCenter vMotion on a VM that has multiple NICs:
Move-VM with Multiple Network Adapters


The above examples are just the tip of showing just how versatile the Move-VM cmdlet really is. Let us know how you’re using Move-VM in your environment in the comments below!

For more information on its use in your environment, see the PowerCLI cmdlet reference on Move-VM.

This entry was posted in General and tagged , , on by .
Kyle Ruddy

About Kyle Ruddy

Kyle Ruddy is a Senior Technical Marketing Engineer at VMware in the Cloud Platform Business Unit. Kyle currently focuses on vSphere with Operations Management as well as all things API, SDK, and CLI. Kyle can be found blogging on VMware blogs, http://blogs.vmware.com/vSphere and http://blogs.vmware.com/PowerCLI, and his personal blog, http://www.thatcouldbeaproblem.com. You can follow Kyle on twitter as @kmruddy.

15 thoughts on “Spotlight on the Move-VM Cmdlet including PowerCLI 6.5 Enhancements

  1. David Warner

    Great stuff. 2 questions.

    1.) Moving VMs across vcenters, does the source and destination ESX hosts have to be able to communicate? Or does only vCenters need to be able to communicate over network to move a VM.

    2.) Is it possible to copy/clone a VM to a different vcenter with PowerCLI?


  2. Josh (Windos) King

    From everything I’m reading this should allow me to move VMs between any vCenter running 6.0 or above, however it errors out for me when I try to move a VM from vCenter 6.5 yo vCenter 6 (Update 2). Is this a bug or intended behavior?

    1. Kyle RuddyKyle Ruddy Post author

      That is not as intended. However there are several reasons that may occur due to some items not being backwards compatible (such as hardware versions, distributed port group versions, etc.).

      I’ll follow up via email to see what the error is.

  3. Pingback: Using PowerCLI to vMotion VM between different SSO domains

  4. Christian

    I got this error message:

    The operation for the entity “VM-Name failed with the following message: “vMotion is not licensed for the Source host

    Both Source and Dest. vCenter are latest 6.0
    Both Source and Dest ESXi Host are 5.5 with E+ license


  5. shreya

    Great article, i understood each and everything about what you said in this article but Is it possible to copy/clone a VM to a different vcenter with PowerCLI?

  6. Chris Childerhose

    How do you keep the same datastore that the VM is on when doing cross vCenter migrations? I have VMs that won’t move in the Web UI due to having multiple VMDKs on multiple datastores due to performance policies like SQL. How do you get around this to keep them on the same shared datastore? I already have moved some hosts to the new VC so each host has the same datastore connections that the ones in the old VC have. I need to get my last 2 hosts moved over to the new VC.

  7. Jeremy Cejka

    I have a question.

    So I am using a variation of this script.

    I am getting this error

    Move-VM : 7/24/2017 3:09:54 PM Move-VM The operation for the entity “testvm” failed with the following message: “Network interface ‘Network adapter 1’ uses
    network ‘DVSwitch: 50 3a a8 89 2a a5 0f 01-2b aa 10 48 7c 56 09 b4’, which is not accessible.”
    At \Untitled3.ps1:27 char:1
    + Move-VM -VM $vm -Destination $destination -NetworkAdapter $networkAdapter -PortG …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Move-VM], CannotAccessNetwork
    + FullyQualifiedErrorId : Client20_TaskServiceImpl_CheckServerSideTaskUpdates_OperationFailed,VMware.VimAutomation.ViCore.Cmdlets.Commands.MoveVM

    The Key for dvswitch is for the destination vcenter.

  8. Fredrik Grafström

    I have made a Powershell gui to migrate VMs. When I migrate VMs between vCenters on the same layer 2 network it works perfect. But I get this error message when migrating VMs between vCenters (and ESXi hosts) on different routed LANs (and locations). It is probably due to a firewall.

    What ports are required to be opened for it to work?

    The VMware support told me TCP port 8000 is required, but is that really correct?

    I get this error message:
    ERROR: 2017-09-28 15:27:59 Move-VM The operation for the entity “vm-rull-tes
    ERROR: t-xyz” failed with the following message: “A general system error occurred:
    ERROR: Host not found (authoritative)” ERROR: At line:1743 char:1
    ERROR: + Main ($CommandLine)
    ERROR: + ~~~~~~~~~~~~~~~~~~~
    ERROR: + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
    ERROR: + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException


  9. Pingback: vMotion between two vCenter Servers with different SSO domains - IVOBEERENS.nl

  10. Askar

    instead of using first host in target environment $destination = Get-Cluster –Name Cluster01 –Server $destVCConn | Get-VMHost | Select-Object –First 1
    it is better to use the following workaround:
    $destination = Get-Cluster –Name Cluster01 –Server $destVCConn get-vmhost | ?{$_.ConnectionState -eq “Connected”}| get-random

    This will allow to choose the hosts not in maintenance mode and distribute the traffic evenly across different hosts if you run few vMotions in parallel.


Leave a Reply

Your email address will not be published. Required fields are marked *