if(-not (Get-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue))
{
Add-PSSnapin VMware.VimAutomation.Core
}
$SubtractMins = New-Object System.TimeSpan 0, 0, 30, 0, 0
$CurTime = Get-Date
$DiffTime = $CurTime.Subtract($SubtractMins)
Connect-VIServer <vcenter name>
Get-VIEvent -Entity $x -start $DiffTime -Finish $CurTime | Export-Csv $p -NoTypeInformation -UseCulture
Oh Sorry, let me try it. Right away.
Please find the output below.
Ok, this confirms what I suspected, there are no events for a cluster entity during the last 30 minutes.
So that explains why nothing is returned.
Which events did you expect to see ?
Sometimes these events are not for the entity you would expect.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes, you are right. There are no events events related to Cluster during the past 30 minutes.
However, I thought of exports "Show all entries" of the cluster.
Please find the screenshot for the events which am looking for "Show all entries"
The difference in what you see is explained by the way both methods work.
In the vSphere client, when you select "Show all entries", it will fetch all events, starting from that entity, recursively.
For example, if there was an event for a VM running in that cluster, you will see that event as well.
The Get-VIEvent cmdlet, when used with the Entity parameter, does not work recursively.
It will only fetch the events for that specific entity.
Similar to what the vSphere client shows when you select "Show cluster entries".
There are some possible solutions:
$clusterName = "MyCluster"
$cluster = Get-Cluster -Name $clusterName
$entity = Get-Inventory -Location $cluster
$entity += $cluster
$start = (Get-Date).AddMinutes(-30)
Get-VIEvent -Entity $entity -Start $start
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you so much LucD.
I am trying the above code and the link about Get-VIEventPlus function works really cool.