gpt4 book ai didi

Powershell Get-EventLog 在远程计算机上挂起

转载 作者:行者123 更新时间:2023-12-03 16:28:22 24 4
gpt4 key购买 nike

以下在本地计算机上运行良好,但是当我输入 -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 的范围似乎并没有真正影响响应时间;两者都很慢。

最佳答案

参数设计得不是很好,它打印了它假设的所有记录,但是当它到达设置日期时,它仍然会扫描到偶数日志文件的末尾,尽管事实上没有什么可打印的(至少看起来如此)。我使用过 Where-object 过滤器和 .CompareTo()打印设置日期之后的日志的方法(在我的情况下是当前日期的前一天)。

#Sets yesterday date (script will get all records after that date)

$YDate = (Get-Date).AddDays(-1)

#Gets all event logs from Security log where event id represents successful logon and records where generated after prepared date (current date - 24 hours)

$YestardayLogons = Get-EventLog -ComputerName $ServerName -LogName Security |
WHERE { ($_.EventId -eq '528') -and ($_.TimeGenerated.CompareTo($YDate) -eq '1') }

关于Powershell Get-EventLog 在远程计算机上挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22175885/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com