Automation

 View Only
  • 1.  How to track move-vm start and completion time

    Posted Apr 24, 2019 05:16 AM

    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



  • 2.  RE: How to track move-vm start and completion time

    Posted Apr 24, 2019 06:25 AM

    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.



  • 3.  RE: How to track move-vm start and completion time

    Posted Apr 24, 2019 06:38 AM

    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.



  • 4.  RE: How to track move-vm start and completion time

    Posted Apr 24, 2019 06:57 AM

    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.



  • 5.  RE: How to track move-vm start and completion time

    Posted Apr 24, 2019 07:07 AM

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



  • 6.  RE: How to track move-vm start and completion time

    Posted Apr 24, 2019 07:49 AM

    Try something like this (this looks at the last day)

    $events = Get-VIEvent -Start (get-Date).AddDays(-1) -MaxSamples ([int]::MaxValue)

    $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

       }

       }

    }