Why is Get-WinEvent slower than Get-EventLog when getting events after a date?

做~自己de王妃 提交于 2021-02-18 13:57:46

问题


When retrieving events after a specific date Get-WinEvent seems to be slower than Get-EventLog:

$SourceComputer = "MyServer"
$LogName = "Security"
$StartDate = (get-date).AddMinutes(-30)
$hashquery = @{logname=$LogName; StartTime=$StartDate}
(Measure-Command -Expression {Get-WinEvent -ComputerName $SourceComputer -FilterHashTable $hashquery}).TotalSeconds
(Measure-Command -Expression {Get-EventLog -Computer $SourceComputer -LogName $Logname -After $StartDate}).TotalSeconds

Output:

Get-WinEvent: 128.8475308
Get-EventLog: 4.5299092

This seems odd since Get-WinEvent is supposed to perform better that the older Get-EventLog function. Am I doing something wrong?


回答1:


...Get-WinEvent is supposed to perform better that the older Get-EventLog...

With most parameters, this is correct. Get-WinEvent is faster than Get-EventLog, because Get-EventLog grabs the entire EventLog, then locally filters.

However, Get-WinEvent does have a few caveats, the first being -FilterHashtable which has a few bugs.

The second being that -FilterHashtable is very slow as per the bottom of the blog post cited by Ansgar Wiechers. The recommendation is to use -FilterXML




回答2:


According to this blog post, Get-EventLog seems to be significantly slower when used against remote hosts.



来源:https://stackoverflow.com/questions/16731635/why-is-get-winevent-slower-than-get-eventlog-when-getting-events-after-a-date

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!