VMware Cloud Community
spatrayuni
Contributor
Contributor

Get-VIEvent is unable to get the data of the last 1 hour

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

0 Kudos
25 Replies
spatrayuni
Contributor
Contributor

Oh Sorry, let me try it. Right away.

0 Kudos
spatrayuni
Contributor
Contributor

Please find the output below.Output.JPG

0 Kudos
LucD
Leadership
Leadership

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

0 Kudos
spatrayuni
Contributor
Contributor

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"

Events.JPG

0 Kudos
LucD
Leadership
Leadership

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:

  • You do not use the Entity parameter, and you filter out the required events yourself by checking the Entity property in the returned events
  • You "simulate" recursion, by passing all entities that exists below the cluster.
$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

  • You use the API directly, there is an option to make it return events recursively. An example is my Get-VIEventPlus function in Get the vMotion/svMotion history


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

0 Kudos
spatrayuni
Contributor
Contributor

Thank you so much LucD. Smiley Happy

I am trying the above code and the link about Get-VIEventPlus function works really cool.

0 Kudos