VMware Cloud Community
Mallik7
Enthusiast
Enthusiast

Is there a script available to know how many times a virtual machine has migrated off to different hosts in last 24-48hrs ?

Is there a script available to know how many times a virtual machine has migrated off to different hosts in last 24-48hrs?

Reply
0 Kudos
14 Replies
LucD
Leadership
Leadership

Have a look at my Events – Part 8 – VMotion History post.


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

Reply
0 Kudos
Mallik7
Enthusiast
Enthusiast

thanks for the script. However, it is missing to list the "host names" and Time1 and Time2 and Host2 information.

Reply
0 Kudos
LucD
Leadership
Leadership

If Host2 and Time2 are empty, you are most probably looking at an svMotion, not a vMotion.
The value in Host1 is directly obtained from the event, if that is missing, there might be an issue with your events.

Can you share what you are seeing?


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

Reply
0 Kudos
Mallik7
Enthusiast
Enthusiast

I'm looking for vmotion information only (when resources are required, the VMs will get migrated between the hosts), not for the storage vmotion.

please find attached the output -

Reply
0 Kudos
LucD
Leadership
Leadership

In that case, try like this

$start = (Get-Date).AddDays(-1)

Get-VIEvent -Start $start -MaxSamples ([int]::MaxValue) |

where{$_ -is [VMware.Vim.VmMigratedEvent] -or $_ -is [VMware.Vim.VmRelocatedEvent]} |

Select CreatedTime,@{N='VM';E={$_.VM.Name}},

   @{N='From';E={$_.SourceHost.Name}},

   @{N='To';E={$_.Host.Name}}


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

Reply
0 Kudos
Mallik7
Enthusiast
Enthusiast

throwing the error message - please find attached

Reply
0 Kudos
Mallik7
Enthusiast
Enthusiast

HI Luc, did you get a chance to look the attached screenshot.... kindly help...

Reply
0 Kudos
LucD
Leadership
Leadership

That is a known error. It was fixed in the recent releases of PowerCLI.

Please upgrade your PowerCLI installation


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

Reply
0 Kudos
Mallik7
Enthusiast
Enthusiast

ok, to which version needs to be upgraded to fix the problem and get the expe, please advise....

Reply
0 Kudos
LucD
Leadership
Leadership

If I remember correctly in 11.3.0.


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

Reply
0 Kudos
Mallik7
Enthusiast
Enthusiast

thanks, I see some result after upgrading. can this be run for a single server or for couple of servers, instead a whole vCenter ....!

Reply
0 Kudos
LucD
Leadership
Leadership

The events are kept on the VCSA, so you will in any case have to connect to the vCenter.

You can of course use a Where-clause to filter the events for a specific ESXi node.

The Entity parameter is another option, but some of these vMotion are triggered by DRS, those will not found in that case.

In conclusion, get them all and use a Where-clause for filtering on one or more ESXi nodes.


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

Reply
0 Kudos
Mallik7
Enthusiast
Enthusiast

I'm in need of only couple of VMs vmotion events information from the past one month.

When I run the script for 30 days and for entire vCenter (vCenter has about 1000+ VMs), I guess, it takes days to capture all the events.

could you help please...!

Reply
0 Kudos
LucD
Leadership
Leadership

If you know the VMs for which you are looking up the events, you can pass those on the Entity parameter.

That would at least make the query faster.


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

Reply
0 Kudos