VMware Cloud Community
Alexandre2
Contributor
Contributor

VM migration to another datacenter / cluster / array and folders

Hi all,

I need to migrate 2000 VMs from one datacenter to another, change arrays and folders too.

Below my configuration:

Datacenter1 - Source cluster - Source Array

Datacenter2 - Target cluster - Target Array

I want to migrate from the SAN because it's more quicker. So I've a LUN (target array) dedicated to the migration only, it has been masked on both clusters.

I propose to do theses actions:
1) SVMotion on dedicated migration LUN
2) vMotion target cluster
3) SVmotion target LUN (target array)
4) Folder migration (if it not exist on the target datacenter)

Could you have ideas to script this on Powercli ?

Reply
0 Kudos
3 Replies
LucD
Leadership
Leadership

Yes, I could


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

Alexandre2
Contributor
Contributor

I begin with this script but I have an error when I want to do a vMotion on another cluster

$csvinput = $args[0]

import-csv $csvinput | foreach {
$name = $_.Name
$clustercible = $_.clustercible
$targetds = $_.targetds
$ds1=get-datacenter "dc_old" | Get-Datastore | where {$_.Name -eq "DSD_migration"}
$ds2=get-datacenter "dc_maq" | Get-Datastore | where {$_.Name -eq "DSD_migration"}

Get-VM ($name) | Move-VM -Datastore $ds1 -RunAsync -Confirm:$false
Get-VM ($name) | Move-VM -Destination $clustercible -Datastore $ds2  
}

 

I have this error:

Move-VM : 17/11/2021 12:20:07 Move-VM Object reference not set to an instance of an object.
At D:\Alexandre\Script\test1.ps1:40 char:18
+ Get-VM ($name) | Move-VM -Destination $clustercible -Datastore $ds2
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Move-VM], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.MoveVM

Reply
0 Kudos
Alexandre2
Contributor
Contributor

I've updated my script and powercli version to 12.4 but the problem is always present. Below the script and the output:

import-csv $csvinput | foreach {
$name = get-vm $_.Name
$clustercible = get-cluster $_.clustercible
$targetds = get-datastorecluster $_.targetds
$ds1=get-datacenter "dc_old" | Get-Datastore | where {$_.Name -eq "DSD_migration"}
$ds2=get-datacenter "dc_maq" | Get-Datastore | where {$_.Name -eq "DSD_migration"}

#Get-VM ($name) | Move-VM -Datastore $ds1 -RunAsync -Confirm:$false
#Get-VM ($name) | Move-VM -Destination $clustercible -Datastore $ds2
Move-VM -VM $name -Destination $clustercible -Datastore $ds2
$vm.ExtensionData.RelocateVM($spec, [VMware.Vim.VirtualMachineMovePriority]::defaultPriority)
}


PS D:\Alexandre\Script> .\test1.ps1 .\liste_VMs.csv

Name Port User
---- ---- ----
vcenter 443 xxxxxxxxxx
Move-VM : 18/11/2021 09:21:43 Move-VM Object reference not set to an instance of an object.
At D:\Alexandre\Script\test1.ps1:24 char:1
+ Move-VM -VM $name -Destination $clustercible -Datastore $ds2
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Move-VM], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.MoveVM

 

Do you have ideas to resolve this problem ?

 

Reply
0 Kudos