在特定日期之后检索事件时,Get-WinEvent 似乎比 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
输出:
Get-WinEvent: 128.8475308
Get-EventLog: 4.5299092
这似乎很奇怪,因为 Get-WinEvent 应该比旧的 Get-EventLog 函数执行得更好。难道我做错了什么?