VMware Cloud Community
meistermn
Expert
Expert
Jump to solution

relocate vm's from csv file and create schedule task in VC

What is wrong with the last line "$scheduledTaskManager.CreateScheduledTask($vmView.MoRef, $task) " ?

  1. The ScheduledTaskManager is in the Service Instance.

$si = get-view ServiceInstance

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

  1. 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

*

}

  1. 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)

Reply
0 Kudos
24 Replies
meistermn
Expert
Expert
Jump to solution

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.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

No need to create a new thread for now.

The GetAdmin blog contains indeed some treasures Smiley Wink


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

Reply
0 Kudos
meistermn
Expert
Expert
Jump to solution

Hello Luc ,

following line can be changed .

$spec.Description = "Migrate " + $_.VMname + " to " + $tgtDatastore

$spec.Description = "Migrate " + $_.VMname + " to " + $_.Datastore

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Correct, forgot that one.


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

Reply
0 Kudos
vm-au-user
Contributor
Contributor
Jump to solution

I'd like to build on the scrip to add the ability,


* shutdown the vm (a requirement for a host & datastore migration)
* select the host & datastore for migration
I see the datastore criteria is already included, what command can I add to request the input of host?
Get-Admin blog doesn't appear to running anymore
Reply
0 Kudos