Poor Windows Event Query Performance on WEC with unknown Event Source

TheGrea 11 Reputation points
2024-01-03T10:32:21.64+00:00

Hi,

we have an issue, that it's really slow to query Windows Events on a Windows Event Collector e.g via Get-WinEvent when the Source is unknown (The description for Event ID xx from source yy cannot be found).

You can see in the API Monitor, that it takes quite long to execute EvtOpenPublisherMetadata:

Snap2

Content Format is set to Events and not RenderedText

If you copy the Registry Key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\Application%Source%

from the source system that generated the event and set it on the Windows Event Collector the performance to query these events are about 10x times faster. Futhermore you don't see no more error codes 2 when executing EvtOpenPublisherMetadata and the calls also way faster.

Is there a way to solve this performance issue without registering every source on the Event Collector Server ?

Thanks in advance

Windows development | Windows API - Win32
Windows for business | Windows Server | User experience | PowerShell
Windows for business | Windows Server | User experience | Other
Windows for business | Windows Client for IT Pros | User experience | Other
{count} votes

1 answer

Sort by: Most helpful
  1. MotoX80 36,291 Reputation points
    2024-01-05T23:58:26.43+00:00

    See if this works for you. I discovered that if you point wevtutil.exe directly at the event log .evtx file, it won't try to process the EventMessageFile. It just dumps the XML. I traced it with Process Monitor and did not see any eventlog registry reads. I used my Application log to test.

    cls
    $xml = New-Object -TypeName XML
    $data =  wevtutil.exe qe /c:10 /rd:true /lf C:\Windows\System32\winevt\Logs\Application.evtx
    $data = "<AllEvents>" + $data + "</AllEvents>"
    $xml.LoadXml($data)
    foreach ($e in $xml.AllEvents.Event) {
        [PSCustomObject] @{
            TOD = ([datetime]($e.System.TimeCreated).SystemTime).ToString("yyyy-MM-dd HH:mm:ss")
            EventID = $e.System.EventID.'#text'
            Provider = $e.System.Provider.Name
            Data = $e.EventData.Data -join ","
        }
    }
    
    
    

    The down side to this is that even if the event source is registered, you won't get the formatted message, you just get the data that plugs into the message.

    User's image

    User's image

    User's image

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.