Hello, horningj-
I worked out a couple of items that should grab the event category. The first selects a few properties, including a calculated property that gets the event category:
## works well if no events of type 'EventEx'
## get the .Net View object of the EventManager (used for getting the event Category)
$viewEventMgr = Get-View EventManager
## get some VIEvents, select a few properties, including a calculated property for EventCategory
Get-VIEvent | Select FullFormattedMessage, CreatedTime, @{n="EventCategory"; e={$strThisEventType = $_.GetType().Name; ($viewEventMgr.Description.EventInfo | ?{$_.Key -eq $strThisEventType}).Category}}
This gets VIEvents (the latest 100, as I did not specify the -MaxSamples parameter), and returns the given properties. The "EventCategory" calculated property uses the VIEvent object's type to look in the collection of EventDescriptionEventDetail items in the eventInfo property found in the .Net View object for the EventManager. It then grabs the "Category" property of the corresponding EventDescriptionEventDetail item.
Works pretty well unless you have any VIEvents of type "EventEx" -- then, this method of "lookup" in the EventDescriptionEventDetail collection fails, as there are more than one item of that type (there are 91 of them at the moment).
This led me to the next bit. It is similar to the previous method, but it handles EventEx events, too:
## get the .Net View object of the EventManager (used for getting the event Category)
$viewEventMgr = Get-View EventManager
## get some VIEvents (the last 100, as "-MaxSamples" is not specified)
Get-VIEvent | %{
## put the pipeline varible into another variable; get its type
$oThisEvent = $_; $strThisEventType = $_.GetType().Name
## if this event is of type "EventEx"
if ($strThisEventType -eq "EventEx") {
$strEventTypeId = $oThisEvent.EventTypeId;
## get the EventInfo item (of type EventDescriptionEventDetail) whose "FullFormat" property begins with the EventTypeId of the VIEvent at hand, and get its "Category" property
$strCategory = ($viewEventMgr.Description.EventInfo | ?{$strRegexPattern = "^$strEventTypeId\|.*"; $_.FullFormat -match $strRegexPattern}).Category
} ## end if
## else, can just grab the EventInfo item whose "Key" is the same as this event's type
else {$strCategory = ($viewEventMgr.Description.EventInfo | ?{$_.Key -eq $strThisEventType}).Category}
## add a NoteProperty "EventCategory" to this event
$oThisEvent | Add-Member -MemberType NoteProperty -Name EventCategory -Value $strCategory -PassThru
} | Select FullFormattedMessage, CreatedTime, EventCategory
It appears that the EventTypeId of the event returned from Get-VIEvent is included as the first part of the FullFormat property of EventDescriptionEventDetail items with the key EventEx, delimited from the rest of the value by a vertical pipe. So, the EventTypeId from the VIEvents can be used to do a match on the EventEx types of events from the EventManager .Net View object to get the event "category" (info, warning, error, user).
You can, of course, change up the Select statements to pick/choose the pieces of info that you would like to export, and then export them to some data file as you please.
How does that do for you?
* Message was edited by mattboren on 05 Apr 2011 -- added line to start of second piece of code "$viewEventMgr = Get-View EventManager". This was already in the first piece and assumed that user was running both pieces in same session, but added for completeness.