【发布时间】:2014-04-06 05:17:01
【问题描述】:
以下在本地计算机上运行良好,但是当我输入 -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 的范围似乎并没有真正影响响应时间;两者都很慢。
【问题讨论】:
-
尝试一些应该运行得更快的方法,例如
Get-EventLog -logname application -computername myRemoteName -newest 10。如果这种情况很快恢复,那么您的原始命令可能会发现比您想象的更多的错误。如果没有,那么可能是一些配置问题。 IIRC 此命令使用 DCOM 进行连接。 -
我用你的 -newest 参数替换了我的 -after 参数(我放了 -newest 2),它很快就回来并发送了电子邮件。最后两个错误发生在午夜左右。这是我的 Prod 系统,我可以登录到 App Event viewer 并验证应用程序事件日志中的错误数量。我已经在 QA 环境中运行这个脚本几个月了(但没有 -ComputerName 参数)。我们在 Prod 中有旧版本的 Powershell,所以我想远程运行。嗯……那现在呢?
-
它最终还是返回了原始代码,但我在其他机器上没有看它,所以不知道花了多长时间。我现在正在重新运行 Get-EventLog 之前和之后的时间打印。 -after 过滤器是否在远程计算机上运行?
-
因此没有任何连接/配置问题妨碍您。您的 $minutes 变量设置为什么?也许你会比你想象的更远地回到历史?
-
尝试 Get-WinEvent 看看是否运行得更快
Get-WinEvent -cn myRemoteName -FilterHashtable @{LogName='Application'; Level=2; StartTime=(Get-Date).AddMinutes($minutes * -1)}。