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.
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
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
Thanks guru 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
Hi Luc
Still not showing IP address with the given script in output.
Below is the attached output.
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
Yes Luc, Tool are OK for these vms.
There was a typo in the previous code, I corrected it.
Please try again.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Excellent Luc 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.
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
Thanks Luc for update.Ill go through the link given.