VMware Cloud Community
kwg66
Hot Shot
Hot Shot
Jump to solution

move-vm thinks I'm trying to migrate to a different vCenter

Hi Folks - amateur scripter here - 

I created a simple script to evacuate our hosts licensed with standard licensing without DRS capability.   

After connecting to vCenter, it is as follows:

$vccluster = Read-Host "Input the cluster name at the prompt"
 
$VMhost = Read-Host "Input the vSphere host to evacuate"
 
$esx = Get-VMHost -Location $vccluster | Get-Random
 
$VM = Get-VM -Location $VMhost
 
Move-VM -VM $VM -Destination $esx

 

This script works to move all VMs, even powered off, to other hosts in the cluster after typing in the cluster and host to evacuate. 

Oddly, for every VM that resides on the host the following error is generated:

Move-VM : 2/26/2024 4:18:41 PM Move-VM When migrating a VM to a different vCenter Server both Destination and Datastore need to be specified. No other destination types but VMHost/Resource Pool and Datastore are supported for Cross vCenter vMotion
At C:\Users\kwg\Desktop\evacuation_test_2.ps1:12 char:1
+ Move-VM -VM $VM -Destination $esx
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Move-VM], VimException
    + FullyQualifiedErrorId : Client20_VmHostServiceImpl_CheckMoveVmParameters_BothDestinationAndStorageRequiredForXVCVmotion,VMware.VimAutomation.ViCore.Cmdlets.Commands.MoveVM
 

Can someone shed light on why I am seeing this error despite the script working?   Also, is it possible to change the $VM parameter to only include powered on VMs?  

Thanks

 

 

Labels (1)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Could it be that you have more than 1 vCenter connection open?
Check what it says in $global:defaultVIServers


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

Could it be that you have more than 1 vCenter connection open?
Check what it says in $global:defaultVIServers


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

0 Kudos
kwg66
Hot Shot
Hot Shot
Jump to solution

Apparently that was it, I don't recall trying to connect to any other VCenter.  I am forced to re-authenticate each time i connect even when I don't disconnect but that I believe has to do with the appliance - https://kb.vmware.com/s/article/2050701.  

I added in the code I need to only migrate powered on VMs.   

 
$VM = (Get-VM -Location $VMhost).where{$_.PowerState -eq 'PoweredOn'} 
 
Thanks 
0 Kudos