What is wrong with the last line "$scheduledTaskManager.CreateScheduledTask($vmView.MoRef, $task) " ?
The ScheduledTaskManager is in the Service Instance.
$si = get-view ServiceInstance
$scheduledTaskManager = Get-View $si.Content.ScheduledTaskManager
We need to identify the VM and the host where it will be powered on.
#$vmView = Get-VM PowerOnTest | Get-View
#$esxView = Get-VMHost esx35-01.vitoolkit.local | Get-View
foreach ($f in (import-csv `
"D:\MigrateStorage\amsterdam-core-hp-poweron.csv"))
{
$vmView=$f
*
echo $vmView
*
}
Now we construct the task argument.
$arg = New-Object VMware.Vim.MethodActionArgument
#$arg.Value = $esxview.MoRef
$action = New-Object VMware.Vim.MethodAction
$action.Argument = $arg
$action.Name = "PowerOnVM_Task"
$scheduler = new-object VMware.Vim.OnceTaskScheduler
$scheduler.runat = (get-date).addminutes(5)
$task = New-Object VMware.Vim.ScheduledTaskSpec
$task.Action = $action
$task.Description = "Start a VM with a scheduled task."
$task.Enabled = $true
$task.Name = "Power On Virtual Machine"
$task.Scheduler = $scheduler
$scheduledTaskManager.CreateScheduledTask($vmView.MoRef, $task)
Hello Ludc,
should I start a new thread to give more Points. I already migrated with our scripts 321 VM. That is about 17 TB. Now the next 274 VM's (18 TB) will be migrated.
From the following script two cool improvents can be made.
While ($DestView.Info.FreeSpace -> This checks if enough space is on the datastore
$MaxConcurrent = 2 and RunAsync | Wait-task -> this checks when the task is finished and starts the next motion.
No need to create a new thread for now.
The GetAdmin blog contains indeed some treasures
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello Luc ,
following line can be changed .
$spec.Description = "Migrate " + $_.VMname + " to " + $tgtDatastore
$spec.Description = "Migrate " + $_.VMname + " to " + $_.Datastore
Correct, forgot that one.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I'd like to build on the scrip to add the ability,