VMware Cloud Community
tangodisco1
Contributor
Contributor

Cross vCenter vMotion EVC Precheck Script

Hello! I was wondering if you could help me out with a script I've been attempting to get to work.

Basically, what I intend to do is check if a VM will have EVC issues before it migrates from one vCenter to another, both of which are not in Linked Mode.

This is the code I have so far:

$global:DefaultVIServers.Name

$sourceVC = "sourcevc.vsphere.local"

$sourceVCUsername = "user@vsphere.local"

$sourceVCPassword = "password"

$destVC = "destvc.vsphere.local"

$destVCUsername = "user@vsphere.local"

$destVCpassword = "password"

$vm = "nameofVM"

$vhost = "nameofhost.domain.net"

if(Connect-VIServer -Server $sourceVC -user $sourceVCUsername -password $sourceVCPassword -ErrorAction Ignore)

{    

   Write-Host "Source vCenter $sourceVC Connected"  -ForegroundColor Cyan   

}

else

{

    Write-Host "Failed to Connect vCenter $vc"  -ForegroundColor Cyan

}

if(Connect-VIServer -Server $destVC -user $destVCUsername -password $destVCpassword -ErrorAction Ignore)

{    

   Write-Host "Destination vCenter $destVC Connected"  -ForegroundColor Cyan   

}

else

{

    Write-Host "Failed to Connect vCenter $vc"  -ForegroundColor Cyan

}

$viewSI = Get-View "ServiceInstance"

$viewVmProvChecker = Get-View $viewSI.Content.VmProvisioningChecker

$VM = Get-View (Get-VM -Server $sourceVC -Name $vm)

$VMHost = Get-VMHost -Server $destVC -Name $vhost

{

$viewVmProvChecker.QueryVMotionCompatibilityEx($VM.Id, $VMHost.Id)

} | Select-Object @{N="VM";E={($_.Vm | Get-VIObjectByVIView).Name}},

@{N="VMHost";E={($_.Host | Get-VIObjectByVIView).Name}},

@{N="Warning";E={[string]::Join(',',($_.Warning | %{$_.LocalizedMessage}))}},

@{N="Error";E={[string]::Join(',',($_.Error | %{$_.LocalizedMessage}))}},

LinkedView,

DynamicType,

DynamicProperty |

Export-Csv -Path "C:\Users\Test\Desktop\EVCCheck.csv" -NoTypeInformation -UseCulture

However the output always comes out as either empty, or fails with the following errors, depending on whether I declare $VM.Id or $VM.MoRef in the QueryVMotionCompatibilityEx sentence:

______________________________________________

Exception calling "QueryVMotionCompatibilityEx" with "2" argument(s): "

Required parameter vm is missing

while parsing call information for method QueryVMotionCompatibilityEx_Task

at line 1, column 171

while parsing SOAP body

at line 1, column 64

while parsing SOAP envelope

at line 1, column 0

while parsing HTTP request for method queryVMotionCompatibilityEx

on object of type vim.vm.check.ProvisioningChecker

at line 1, column 0"

At line:1 char:1

+ $viewVmProvChecker.QueryVMotionCompatibilityEx($VM.Id, $VMHost.Id)

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : VimException

______________________________________________

or more commonly:

______________________________________________

Exception calling "QueryVMotionCompatibilityEx" with "2" argument(s): "The object 'vim.VirtualMachine:vm-1234567' has

already been deleted or has not been completely created"

At line:1 char:1

+ $viewVmProvChecker.QueryVMotionCompatibilityEx($VM.MoRef, $VMHost.Id)

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : VimException

______________________________________________

Could anyone tell me whether they've attempted to write a script like this or rather where I'm going wrong with the execution?

Is it possible to do this script at all? Maybe it's not contemplated at all in the QueryVMotionCompatibilityEx function.

Thanks in advance!

7 Replies
LucD
Leadership
Leadership

Did you already try with the MoRef property?

$viewVmProvChecker.QueryVMotionCompatibilityEx($VM.MoRef, $VMHost.ExtensionData.MoRef)


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

tangodisco1
Contributor
Contributor

Hello LucD! Thanks for your input. However I tried with both ($VM.Id, $VMHost.ExtensionData.MoRef) and ($VM.MoRef, $VMHost.ExtensionData.MoRef) and while they don't throw out any errors, the output of the .CSV file is nothing apart from the name of the columns.

Do you by any chance have any other insight into why this could be working like this? I forgot to add that this code works intra-vCenter, as in checking from cluster to cluster within a same vCenter.

Thanks in advance!

Reply
0 Kudos
LucD
Leadership
Leadership

Are you sure this method is supported cross-vCenter?

Could you try a test run with a VM and the ESXi node on the same vCenter?


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

Reply
0 Kudos
tangodisco1
Contributor
Contributor

LucD, indeed I ran this script against different clusters inside the same vCenter, and also using a VM which had an EVC level above the other hosts in the same cluster, and both worked properly.

I haven't been able to find any documentation on QueryVMotionCompatibilityEx function apart from the following:

https://vdc-repo.vmware.com/vmwb-repository/dcr-public/b525fb12-61bb-4ede-b9e3-c4a1f8171510/99ba073a...

In any case, may I ask if you've ever come across any script or attempt to check EVC levels before vMotion between two different vCenter Servers?

Thanks for your help!

Regards

Reply
0 Kudos
LucD
Leadership
Leadership

I'm afraid not.


I know William did several posts on cross-vCenter vMotion, but I don't remember seeing the use of the QueryVMotionCompatibilityEx_Task method in any of those.


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

Reply
0 Kudos
LucD
Leadership
Leadership

Btw, there is a recent, excellent post on cross-vCenter vMotion out, see 5 Core Requirements for Cross vCenter Migrations

That lists the requirements, but no mention of checking either.


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

Reply
0 Kudos
tangodisco1
Contributor
Contributor

Thanks LucD! I opened up a support case with VMware support to see if they can help me out with this.

If anyone else knows or tried this and wants to help all assistance is welcome!

Regards

Reply
0 Kudos