VMware Cloud Community
edelldieguez
Contributor
Contributor

Storage vMotion and vMotion VMs to Several Datastores and New Cluster

Hi Guys,

I have a script for svmotion and i would like to modify it to move several vms from diferent .csv files to a different datastores and new Cluster, here is the script:

##### svMotion VMs #####


# Import the csv with the VMs i want to svMotion
$vmNames = Import-Csv "C:\svMotionVMs1.csv" -UseCulture | %{$_.vmName}

# svMotion VMs provided in the csv to VMFS_DATA_1
$svmVMs = Get-VM -Name $vmNames
foreach ($vm in $svmVMs)
{
write-progress -Activity svMotion -Status "Moving $vm"
Move-VM $vm -Datastore VMFS_DATA_1 -Confirm:$false -RunAsync
}

we have 20 VMs that we want to migrate to a new Cluster and new Datastores:

OldCluster has 20VMs in different DataStores

NewCluster

DataStore 1

DataStore 2

DataStore 3

DataStore 4

I created 4 .csv files with the names of the VMs called svMotionVMs1.csv, 2, 3 and 4, will be possible ex: take the VMs in the svMotionVMs1.csv and put those VMs in DataStore 1 and NewCluster, svMotionVMs2.csv and put those VMs in DataStore 2 and NewCluster and so on but using only one script?, it will start with the first csv and when is done, start with the second until it finished with all svMotionVMs.csv ?.

All VMs will be turn off for the migration and that is why i would like to do vMotion and svMotion at the same time.

Any help will be appreciate, Thanks in advance.

0 Kudos
6 Replies
LucD
Leadership
Leadership

Try it like this

# Import the csv with the VMs i want to svMotion 
1
..4 | %{     $vmNames = Import-Csv "C:\svMotionVMs$_.csv" -UseCulture | %{$_.vmName}     # svMotion VMs provided in the csv to VMFS_DATA_1
    $svmVMs = Get-VM -Name $vmNames
   
foreach ($vm in $svmVMs)     {         write-progress -Activity svMotion -Status "Moving $vm"
        Move-VM $vm -Datastore "VMFS_DATA_$_" -Confirm:$false -RunAsync
    } }


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

0 Kudos
edelldieguez
Contributor
Contributor

Hi LucD,

Thanks for your reply, so the script will look like this right?:

# Import the csv with the VMs i want to svMotion
1..4 | %{
    $vmNames = Import-Csv "C:\svMotionVMs1$_.csv" -UseCulture | %{$_.vmName}

    # svMotion VMs provided in the csv to VMFS_VM_1 to 4
     $svmVMs = Get-VM -Name $vmNames
    foreach ($vm in $svmVMs)
    {
        write-progress -Activity svMotion -Status "Moving $vm"
        Move-VM $vm -Datastore "VMFS_VM_$_" -Confirm:$false -RunAsync
    }
}

Also LucD, will this script move the VMs to the NewCluster or its just for storage vmotion?

Thanks in advance.

0 Kudos
LucD
Leadership
Leadership

Yes, that's hwo the script should look.

The current version does an svMotion.

The target datastore should be visible from both clusters!

You can add another Move-VM with a Destination parameter, pointing to the new cluster, to move the guest over there.


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

0 Kudos
edelldieguez
Contributor
Contributor

LucD,

This will do a vMotion and svMotion at the same time?

# Import the csv with the VMs i want to svMotion
1..4 | %{
    $vmNames = Import-Csv "C:\svMotionVMs1$_.csv" -UseCulture | %{$_.vmName}

    # svMotion VMs provided in the csv to VMFS_VM_1 to 4
     $svmVMs = Get-VM -Name $vmNames
    foreach ($vm in $svmVMs)
    {
        write-progress -Activity svMotion -Status "Moving $vm"

        Move-VM $vm -Destination "NewCluster" -Datastore "VMFS_VM_$_" -Confirm:$false -RunAsync
    }
}

Thanks in advance.

0 Kudos
LucD
Leadership
Leadership

I don't think that will work.

The help states "-Destination or the -Datastore parameters".

You will have to use 2 separate Move-VM lines, I'm afraid.


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

0 Kudos
EKardinal
Enthusiast
Enthusiast

Since vSphere 5.1, you could hot migrate a VM between datastores and hosts in one step.

But that feature is only enabled in the vSphere Web Client and I think, the PowerCLI needs a few more updates to provide this feature as well.

Until then, you have to use two scripts to change datastore and host.

0 Kudos