VMware Cloud Community
RajuVCP
Hot Shot
Hot Shot

Script to get vMotion event scheduled

Hi All,

We are getting failed and success vMotion event in our vCenter. the failed ones VMs are facing performance issues.

would like to see if any one have created script of vMotion events including failed one , succeeded ones. it need to be scheduled and send as email report in html or csv format.

Thanks in Advance.

Raju Gunnal VCP 4, VCP 5, VTSP 4, VTSP 5, ITIL V3 http://www.techtosolution.com
Tags (1)
Reply
0 Kudos
2 Replies
VijayKumarMyada
Enthusiast
Enthusiast

Function Get-MotionDuration {

    $events = Get-VIEvent -Start (Get-Date).AddDays(-7)

    $relocates = $events |

        where {$_.GetType().Name -eq "TaskEvent" -and $_.Info.DescriptionId -eq "VirtualMachine.migrate" -or $_.Info.DescriptionId -eq "VirtualMachine.relocate"}

    foreach($task in $relocates){

        $tEvents = $events | where {$_.ChainId -eq $task.ChainId} |

            Sort-Object -Property CreatedTime

        if($tEvents.Count){

            New-Object PSObject -Property @{

                Name = $tEvents[0].Vm.Name

                Type = &{if($tEvents[0].Host.Name -eq $tEvents[-1].Host.Name){"svMotion"}else{"vMotion"}}

                StartTime = $tEvents[0].CreatedTime

                EndTime = $tEvents[-1].CreatedTime

                Duration = New-TimeSpan -Start $tEvents[0].CreatedTime -End $tEvents[-1].CreatedTime

            SourceHost = $tEvents[0].Host.Name

            DestinationHost = $tEvents[-1].Host.Name

            }

        }

    }

}

Connect-VIServer MyViServer –User Administrator –Password “XXXXXX

Get-MotionDuration | FT -AutoSize

Reply
0 Kudos
RajuVCP
Hot Shot
Hot Shot

Thanks for response Vijay,

this is something already happened vMotion events.

I was looking for something vMotion events both failed and succeeded one , it should send them as scheduled report in html format.

Raju Gunnal VCP 4, VCP 5, VTSP 4, VTSP 5, ITIL V3 http://www.techtosolution.com
Reply
0 Kudos