VMware Cloud Community
VM_
Contributor
Contributor

vCenter Scheduled Tasks - Cold Migrate 250 VMs to new cluster

Hi All,

I've been attempting to modify the LucD script in the following link:

http://www.lucd.info/2009/10/18/scheduled-tasks-methodaction/

I would like to schedule the cold migration (different cpu type in new cluster) of 250+ VM's to a new Nutanix cluster. I have the following:

$csvName = "vms_to_migrate.csv"

$tgtCluster = "Cluster Name"

$tgtHost = "Host Name"

$emailAddr = "email@domain.com"

$startTime = [System.DateTime]::Parse("17/04/2015 17:00") # Ex [Datetime]"10/21/2009 20:00"

#$startInterval = 1

$si = get-view ServiceInstance

$scheduledTaskManager = Get-View $si.Content.ScheduledTaskManager

$csv_info = Import-Csv $csvName

foreach ($line in $csv_info)

{

  $vm = Get-View -ViewType VirtualMachine -Filter @{"Name"=$line.Name}

  $spec = New-Object VMware.Vim.ScheduledTaskSpec

  $spec.Name = "vMotion " + $line.Name

  $spec.Description = "Compute Migrate " + $tgtCluster

  $spec.Enabled = $true

  $spec.Notification = $emailAddr

  $spec.Scheduler = New-Object VMware.Vim.OnceTaskScheduler

  $spec.Scheduler.runat = $startTime #$startTime.AddMinutes($offset)

  #$offset += $startInterval

  $spec.Action = New-Object VMware.Vim.MethodAction

  $spec.Action.Name = "RelocateVM_Task"

  $arg1 = New-Object VMware.Vim.MethodActionArgument

  $arg1.Value = New-Object VMware.Vim.VirtualMachineRelocateSpec

  $arg1.Value.pool = (Get-Cluster $tgtCluster | Get-View).MoRef

  $arg1.Value.host = (Get-VMHost $tgtHost | Get-View).MoRef

  $spec.Action.Argument += $arg1

  $arg2 = New-Object VMware.Vim.MethodActionArgument

  $arg2.Value = [VMware.Vim.VirtualMachineMovePriority]"defaultPriority"

  $spec.Action.Argument += $arg2

  $scheduledTaskManager.CreateScheduledTask($vm.MoRef, $spec)

}

I get an error: A specified parameter was not correct.

I have tried to use Onyx to get the details I need but it hangs everytime I manually create a cold migration scheduled task. (Version Onyx_2.2.5161.29309)

Any help much appreciate as we have a project that has tight deadline and the existing scripted sequential migrations are taking too long.

Any help appreciated.

0 Kudos
3 Replies
LucD
Leadership
Leadership

Seems to be working for me, at least I don't get the parameter error message.

Somethings to check.

Are you sure your Get-View is only returning 1 object, remember the filter is a RegEx expression.

Perhaps try like this

  $vm = Get-View -ViewType VirtualMachine -Filter @{"Name"="^$($line.Name)$"}

Shouldn't you also specify a datastore in the relocationspec ?


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

VM_
Contributor
Contributor

Thanks for advise. The datastore is not changing in this move and is accessible to both clusters hardware.

Pretty sure that only a single object is being returned as I have a pre populated csv with unique objects and unique names in vCenter.

0 Kudos
LucD
Leadership
Leadership

Did you have a look in the vpxd log, sometimes there is more information in there why a specific method fails ?


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

0 Kudos