VMware Cloud Community
vin01
Expert
Expert
Jump to solution

Get-VIEvent "vSphere HA restarted virtual machine"

Hi floks

Can anyone help me to complete this script

Get-Cluster "test" |Get-VM | Get-VIEvent |Where-Object {$_.FullFormattedMessage -LIKE 'vSphere HA restarted virtual machine *'} |select ObjectName,@{N="IP addr";E={($_.Guest.IpAddress)}},CreatedTime,FullFormattedMessage

Out put :

ObjectName                          IP addr                             CreatedTime                        FullFormattedMessage             

----------                          -------                             -----------                        --------------------             

VM1                                                         05-Sep-14 4:14:29 PM               vSphere HA restarted virtual ma...

VM2                                                           05-Sep-14 4:14:25 PM               vSphere HA restarted virtual ma...

VM3                                                       05-Sep-14 4:14:25 PM               vSphere HA restarted virtual ma...

Unable to get ipaddress on this script.

pls provide if any good script to get vSphere HA restarted event  when host failure.

Regards Vineeth.K
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try like this

Get-Cluster "test" | Get-VM |

Get-VIEvent |

where {$_.FullFormattedMessage -match "vSphere HA restarted virtual machine"} |

select ObjectName,@{N="IP addr";E={(Get-view -Id $_.Vm.Vm).Guest.IpAddress}},CreatedTime,FullFormattedMessage 

Not sure which property you are trying to get with ObjectName.


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

View solution in original post

Reply
0 Kudos
9 Replies
LucD
Leadership
Leadership
Jump to solution

Try like this

Get-Cluster "test" | Get-VM |

Get-VIEvent |

where {$_.FullFormattedMessage -match "vSphere HA restarted virtual machine"} |

select ObjectName,@{N="IP addr";E={(Get-view -Id $_.Vm.Vm).Guest.IpAddress}},CreatedTime,FullFormattedMessage 

Not sure which property you are trying to get with ObjectName.


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

Reply
0 Kudos
vin01
Expert
Expert
Jump to solution

Thanks guruSmiley Happy I will try this..when I try with Get-VIEvent for a single vm in object name property I got VM name so I selected objectname,I'm learner just stared to develop few scripts..Ignore if  any mistake and is this  correct way to find VMs which are restated by HA after host failure in a cluster or any better way pls suggest.I need output as given above

Regards Vineeth.K
Reply
0 Kudos
vin01
Expert
Expert
Jump to solution

Hi Luc

Still not showing IP address with the given script in output.

Below is the attached output.

Regards Vineeth.K
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Most of the values under the Guest property depend on the fact that the VMware Tools are installed.

Is that the case ? Are the VMware Tools installed ?


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

Reply
0 Kudos
vin01
Expert
Expert
Jump to solution

Yes Luc, Tool are OK for these vms.

Regards Vineeth.K
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

There was a typo in the previous code, I corrected it.

Please try again.


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

Reply
0 Kudos
vin01
Expert
Expert
Jump to solution

Excellent LucSmiley Happy It works perfectly.A small info is this correct way to find VMs which are restated by HA after host failure in a cluster or any better suggession.

Regards Vineeth.K
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Your method is ok (there is no "best" solution in PowerShell).

But I would test on the EventTypeId, that would make the script more independent of the string format in future vSphere releases.

As a matter of fact, I have a post on exactly this. See HA VM failover tracking

With my Get-VIEventPlus function you can directly specify the EventTypeId


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

Reply
0 Kudos
vin01
Expert
Expert
Jump to solution

Thanks Luc for update.Ill go through the link given.

Regards Vineeth.K
Reply
0 Kudos