I have written script for sVmotion of VM from old datastore to new datastore disk by disk. I want to track start and completion time of migration.
$moveVMJob = get-vm -name "$vmname" | Get-HardDisk -Name "$hdd" | Move-HardDisk -Datastore $ds -Confirm:$false
That information is available through the events (provided you have configured your vCenter to keep those records for a sufficiently long time).
Have a look at my Get The VMotion/SvMotion History post.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank You LucD. I have already checked your script it is awesome.
I just wanted to fetch in more granular level of hard disk migration status.
Afaik that information is not retained in the events.
If you want to keep track of that info, you would have to record something yourself.
If you have set the vCenter logging to 'verbose', the information is written to the vpxd log.
But extracting the info from there is not an easy task I'm afraid.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you for your help LucD. i have checked script Get The VMotion/SvMotion History but i am not able to fetch completion time of the task do you have any idea how i can get that..
Try something like this (this looks at the last day)
$events | where{$_ -is [VMware.Vim.VmRelocatedEvent]} |
ForEach-Object -Process {
$chain = $_.ChainId
$chained = $events | where{$_.ChainId -eq $chain} | Sort-Object -Property CreatedTime
$task = $chained | where{$_ -is [VMware.Vim.TaskEvent] -and $_.Info.Name -eq 'RelocateVM_Task'}
if($task){
New-Object PSObject -Property @{
VM = $chained[0].Vm.Name
Type = $task.Info.Name
User = $task.Info.Reason.UserName
Start = $task.Info.QueueTime
Finish = ($chained | where{$_ -is [VMware.Vim.VmRelocatedEvent]}).CreatedTime
}
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference