VMware Cloud Community
LibrarySysadmin
Contributor
Contributor
Jump to solution

Move-VM between ESXi hosts managed by vCenter Server

When I invoke Move-VM to migrate VMs between two ESXi hosts (7.0.2 build 18538813), both managed in the same vCenter Server (7.0.3 build 18778458), I'm receiving errors that appear to conflict.

I want to move both compute and storage from one ESXi host and datastore to a second ESXi host and datastore. Both ESXi hosts are in the same datacenter.
The manual vSphere Client steps are: Migrate > Change both compute and storage resource > Select compute > Select storage > Select networks > Select vMotion priority > Finish.
I want to reproduce that vMotion in PowerCLI. I run into errors that appear to conflict, and I'm not sure what I'm missing:

PowerCLI:
VMware.VimAutomation.Core 12.4.0.18627056

Connect-VIServer -Menu
# connect to both ESXi hosts and to vCenter Server

$vmName = 'web01.domain.tld'
$destESX = 'vm02.domain.tld'
$destDS = 'Primary-vm02'
$vm = Get-VM -Name $vmName
$esx = Get-VMHost -Datastore $destDS -Server $destESX
$ds = Get-Datastore -Name $destDS -Server $destESX

Move-VM -VM $vm -Destination $esx -Datastore $ds

 

When I invoke Move-VM while the ESXi hosts are managed by the vCenter Server, I get the following error:

Move-VM Access to resource settings on the host is restricted to the server that is managing it: 'x.x.x.x'

+ CategoryInfo : NotSpecified: (:) [Move-VM], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.MoveVM

Following KB 2021618, I stop vpxa service and restart hostd on both ESXi servers, then establish a new Connect-VIServer session with each ESXi. When I run Move-VM again, I see this error:

Move-VM This functionality is only available when connected to VMware vCenter Server.

+ CategoryInfo : InvalidOperation: (:) [Move-VM], VimException
+ FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_TryValidateVCConnection_ConnectedToESX,VMware.VimAutomation.ViCore.Cmdlets.Commands.MoveVM

 

I am missing something here. Can you point me in the right direction? Thanks in advance!

 

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

If both those ESXi nodes, source and destination, are managed by the same vCenter, you should only connect to the vCenter.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

4 Replies
LucD
Leadership
Leadership
Jump to solution

When you had that 1st error where you connected to only the vCenter, or where there also connections to the ESXi nodes?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
LibrarySysadmin
Contributor
Contributor
Jump to solution

Thank you for that pointer - I think I was inadvertently only connected to one, instead of all three endpoints. I was running Connect-VIServer individually for each endpoint, instead of for all three at once.

When verifying that my PowerCLI session is connected to both ESXi hosts and vCenter, I get this result:

PS C:\Users\user> connect-viserver -server vm01.domain.tld,vm02.domain.tld,vcenter.domain.tld

Name                           Port  User                          
----                           ----  ----                          
vm01.domain.tld                 443   root                          
vm02.domain.tld                 443   root                          
vcenter.domain.tld              443   VSPHERE.LOCAL\Administrator   

PS C:\Users\user> Move-VM -VM $vm -Destination $esx -Datastore $ds 
Move-VM : 1/14/2022 2:16:31 PM	Move-VM		This functionality is only available when connected to VMware vCenter Server.	
At line:1 char:1
+ Move-VM -VM $vm -Destination $esx -Datastore $ds
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Move-VM], VimException
    + FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_TryValidateVCConnection_ConnectedToESX,VMware.VimAutomation.ViCore.Cmdlets.Commands. 
   MoveVM
 

 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

If both those ESXi nodes, source and destination, are managed by the same vCenter, you should only connect to the vCenter.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

LibrarySysadmin
Contributor
Contributor
Jump to solution

Great, thank you.

I connected my PowerCLI session to only the vCenter, and received the exact same error:

Move-VM		This functionality is only available when connected to VMware vCenter Server.

 

That suggested the problem was my Move-VM syntax, rather than the connection to vCenter. It looks like my command needed to have -Destination parameter set, as well.

I changed my Move-VM command to the following, which ran successfully and had the desired result:

$vm = Get-VM -name 'web01.domain.tld -Location 'vm01.domain.tld'
$destESX = Get-VMHost 'vm02.domain.tld'
$destDS = Get-Datastore 'Primary-vm02' 

$vm | Move-VM -Destination $destESX -Datastore $destDS

Thanks for your help!

0 Kudos