以下在本地计算机上运行良好,但是当我输入 -ComputerName "myRemoteName" 时,它挂起并且即使在大约 5 分钟后也不返回任何内容;但程序似乎仍在运行。
它是否试图通过“线路”返回大量数据?理论上,我在过去 2 小时内远程计算机上的错误应该少于 10 个。
$getEventLog = Get-EventLog -log application -ComputerName "myRemoteName" -after ((get-date).addMinutes($minutes*-1)) -EntryType Error
Write-Host Get-Eventlog completed
# list of events to exclude (based on text found in the message)
$getEventLogFiltered = $getEventLog | Where-Object {$_.Message -notlike 'Monitis*' -and $_.Message -notlike '*MQQueueDepthMonitor.exe*' -and $_.Message -notlike '*The local computer may not have the necessary registry*' }
#to only select certain columns, use Select-Object -Property and list the property/columns
$getEventLogColumns = $getEventLogFiltered | Select-Object -Property TimeGenerated,Source,Message,EntryType,MachineName,EventID
$tableFragment = $getEventLogColumns | ConvertTo-Html -fragment
Write-Host "HTML-Table Built"
之后的代码构建一封电子邮件并发送它......
我看过其他建议切换到 Get-WinEvents 的帖子,但我认为这需要我一两个小时来重写(由于我缺乏使用 Powershell 的经验);我上面的内容在本地计算机上运行良好。
Updates 03/04/2014 13:40 CT:
Running with $minutes = 120 ran 14.5 minutes.
Running with $minutes = 1 ran 12.5 minutes.
结论,改变 $minutes 的范围似乎并没有真正影响响应时间;两者都很慢。