VMware Cloud Community
jedijeff
Enthusiast
Enthusiast

Question on get-vievent


Hi, I am trying to determine the last user to reconfigure a vm. And I believe the only way I have is to use get-vievent and search the full formattted message and then retrienve the user name. However, how can I make get-vievent just retrieve the first(latest) record it finds that matches the formatted message?

0 Kudos
5 Replies
Grzesiekk
Expert
Expert

parameter -MaxSamples 1

check out the examples from : get-help Get-VIEvent -examples  -> ex. number 1 it shows the max samples usage

--- @blog https://grzegorzkulikowski.info
0 Kudos
jedijeff
Enthusiast
Enthusiast

Thank you. I discovered I could simply do a -First 1. I will read this link you sent me though.

0 Kudos
Grzesiekk
Expert
Expert

Actually if you would do  | select-object -first  at the end  that would be a little bit different because when giving -maxsamples 1 you will get only one sample from get-vievent, you could though still make at the end |select-object -first 1 , which clearly would not make much sense, but the thing is you would receive only one. If you would do get-vievent without -maxsample then by default you will receive up to 100 events, from which THEN you do the selecting.

At the end it would be the same result, but it you would measure the time to execute then it would be quicker just to ask for 1 sample rather then getting 100 and then selecting one from the collection.

--- @blog https://grzegorzkulikowski.info
0 Kudos
jedijeff
Enthusiast
Enthusiast

Well the issue is if the event "Task: Reconfigure xx" is in the first 100, or not. That is what I am not sure about.

0 Kudos
LucD
Leadership
Leadership

You might want to have a look at my Events – Part 3 : Auditing VM device changes post.

It uses a TaskCollector to find the reconfiguration task and it's related events.

The filtering for the correct Task object happens on the vSPhere server.


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

0 Kudos