VMware Cloud Community
rxjoseph
Enthusiast
Enthusiast
Jump to solution

Move-VM dosent work to move a VM to a DatastoreCluster for Cross VC Migrations

Hi Experts

I have a Script to do cross VC migration which works perfectly. We use it everyday and its fabulous

Recently we wanted to move a VM which we could not get into one datastore so we used Datastorecluster which is supported by Move-VM

Now if i use a script to move a VM within a Cluster then the Datastorecluster is working.

If i use the same approach for a Cross VC then I get the following error and i need your help please

VM is a alive on the source VC... Migration_Oct_Test

VM will be placed on following ESXi host... vhst6013.mydomain.com

VM Network Adaptor info... Network adapter 1

VM will be moved to following PortGroup...  XXX-VLAN-AAA-BK-VMN

VM will be moved to following datastore...  DSClusterDS_NR

Move-VM : 20-10-2020 17:49:37 Move-VM When migrating a VM to a different vCenter Ser

ver both Destination and Datastore need to be specified. No other destination types b

ut VMHost/Resource Pool and Datastore are supported for Cross vCenter vMotion

At line:120 char:7

+       Move-VM -vm $VM -Destination $destination -NetworkAdapter $netw ...

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

    + CategoryInfo          : InvalidArgument: (:) [Move-VM], VimException

    + FullyQualifiedErrorId : Client20_VmHostServiceImpl_CheckMoveVmParameters_BothD

   estinationAndStorageRequiredForXVCVmotion,VMware.VimAutomation.ViCore.Cmdlets.Co 

  mmands.MoveVM

This part of the script is the one which gives the issue

#################################################################################################

#$destinationDatastore = Get-Datastore $VMdetail.TgDatastore  -ErrorAction SilentlyContinue

    #If  i add the get-datastorecluster then the move VM fails

          $destinationDatastore = get-datastorecluster $VMdetail.TgDatastore  -Server "DestinationVC.Mydomain.com"

         if ($destinationDatastore)  {

           

            Write-Host "VM will be moved to following datastore... " -ForegroundColor Yellow  $destinationDatastore

            }

         Else {

        

            Write-Host " Destination datastore not found" -ForegroundColor Magenta

            Continue

            }

##############################################################################################

#################### SCRIPT####################################

####################################################################################

#        ***Kick off the vMotion VMs between Virtual Centers***

####################################################################################

# vMotion Details

$VMdetails = Get-Content -Path $FileBrowserMigrationDetailsFile |Select-String '^[^#]' | ConvertFrom-Csv -UseCulture

####################################################################################

# Search the VM to be migrated and validate VM if found else skip to next record

# on the CSV

####################################################################################

Foreach ($VMdetail in $VMdetails)  {

         $VM = Get-VM -Name $VMdetail.VMNAME -ErrorAction SilentlyContinue

If ($VM) { 

                        Write-Host "VM is a alive on the source VC..." -ForegroundColor Yellow  $VM

Else { 

                        Write-Host 'VM'  $VMdetail.VMNAME' Cannot be found' -ForegroundColor Magenta

                        continue 

####################################################################################

# Check if there is a Destination ESXi host on the specified cluster

# If found proceed or skip to next record

####################################################################################

       

        

$destination = Get-cluster $vmdetail.TgCluster -ErrorAction SilentlyContinue |Get-VMHost |Select-Object -First 1  #-Name vhst6012.rabobank.corp #

if ($destination){ 

                        Write-Host "VM will be placed on following ESXi host..." -ForegroundColor Yellow $destination 

Else { 

                        Write-host "Destination ESXi host" $vmdetail.TgCluster "is not Accessible"  -ForegroundColor Magenta

                        continue

              

####################################################################################

# Check if the Network Adapter for the VM is found

# If found proceed or skip to next record

####################################################################################

         $networkAdapter = Get-NetworkAdapter -vm $VM -ErrorAction SilentlyContinue

               

If ($networkAdapter){ 

                        Write-Host "VM Network Adaptor info..." -ForegroundColor Yellow $networkAdapter 

Else { 

                        Write-Host "Network Adpater cannot be attahced and migration will fail" -ForegroundColor Magenta

                        continue 

####################################################################################

# Check if the destination vDS switch is available, also check if the destination

# PortGroup is found, if unavailable skip to the next record

####################################################################################

        

         $destinationPortGroup = Get-VDSwitch -Name $VMdetail.TgSwitch -ErrorAction SilentlyContinue |Get-VDPortgroup -Name $VMdetail.TgPortGroup -ErrorAction SilentlyContinue

If ($destinationPortGroup){ 

                        Write-Host "VM will be moved to following PortGroup... " -ForegroundColor Yellow  $destinationPortGroup 

Else { 

                        Write-Host "vDS Switch or PortGroup cannot be found " -ForegroundColor Magenta

                        continue 

                

       

####################################################################################

# Check if the destination Datastore is available if found 

# Proceed , if unavailable skip to the next record

####################################################################################

         #$destinationDatastore = Get-Datastore $VMdetail.TgDatastore  -ErrorAction SilentlyContinue

          $destinationDatastore = get-datastorecluster $VMdetail.TgDatastore  -Server "DestinationVC.Mydomain.com"

         if ($destinationDatastore)  {

           

            Write-Host "VM will be moved to following datastore... " -ForegroundColor Yellow  $destinationDatastore

            }

         Else {

        

            Write-Host " Destination datastore not found" -ForegroundColor Magenta

            Continue

            }

              

}            

####################################################################################

# Move-VM does the actual move of the VM provided all of the above checks are

# Satisfied and completes the migration.

####################################################################################

               

      Move-VM -vm $VM -Destination $destination -NetworkAdapter $networkAdapter -PortGroup $destinationPortGroup -Datastore $destinationDatastore -server vcpbxt001.compute.rabobank.nl| out-null  -ErrorVariable $movevmerr

         if ($movevmerr -eq $null )  {

        Write-host " VM migration in progress ........." -ForegroundColor Magenta

        }

        Else   {

        Write-Host " Move-VM error $movevmerr"

        continue

        }

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

There is a newer version (12.1), but the Release Notes do not mention any changes for Move-VM.

If the problem persists, I suggest opening an SR.

And yes, PowerCLI is supported without a Developer Support contract.

If GSS claims otherwise, point them to PowerCLI Support Breakdown


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

View solution in original post

3 Replies
LucD
Leadership
Leadership
Jump to solution

That looks to be a PowerCLI issue.

Which version are you using?
And on which platform?


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

Reply
0 Kudos
rxjoseph
Enthusiast
Enthusiast
Jump to solution

Hi LucD

I am using

PS C:\> Get-PowerCLIVersion

WARNING: The cmdlet "Get-PowerCLIVersion" is deprecated. Please use the 'Get-Module' cmdlet instead.

PowerCLI Version

----------------

   VMware PowerCLI 12.0.0 build 15947286

---------------

Component Versions

---------------

   VMware Common PowerCLI Component 12.0 build 15939652

   VMware Cis Core PowerCLI Component PowerCLI Component 12.0 build 15939657

   VMware VimAutomation VICore Commands PowerCLI Component PowerCLI Component 12.0 build 15939655

   VMware VimAutomation Vds Commands PowerCLI Component PowerCLI Component 12.0 build 15940185

PowerCLI Version

----------------

   VMware PowerCLI 12.0.0 build 15947286

---------------

Component Versions

---------------

   VMware Common PowerCLI Component 12.0 build 15939652

   VMware Cis Core PowerCLI Component PowerCLI Component 12.0 build 15939657

   VMware VimAutomation VICore Commands PowerCLI Component PowerCLI Component 12.0 build 15939655

   VMware VimAutomation Vds Commands PowerCLI Component PowerCLI Component 12.0 build 15940185

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

There is a newer version (12.1), but the Release Notes do not mention any changes for Move-VM.

If the problem persists, I suggest opening an SR.

And yes, PowerCLI is supported without a Developer Support contract.

If GSS claims otherwise, point them to PowerCLI Support Breakdown


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