7 Replies Latest reply on Oct 9, 2019 1:31 PM by tangodisco1

    Cross vCenter vMotion EVC Precheck Script

    tangodisco1 Lurker

      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!