【问题标题】:Log Monitoring of Multiple Computers with Get-WinEvent使用 Get-WinEvent 监控多台计算机的日志
【发布时间】:2016-09-20 14:27:23
【问题描述】:

从下面的代码行中,有没有办法调用 .txt 文件以获取要查看的计算机列表?我希望它不仅在一台计算机上查找日志,而且从计算机列表中查找。

$StartDate = (get-date).AddHours(-12)
Get-WinEvent -FilterHashtable @{logname="System"; Level=1,2,3; starttime=$StartDate} -ErrorAction SilentlyContinue

希望尽快收到您的来信!谢谢。

【问题讨论】:

    标签: powershell event-log get-winevent


    【解决方案1】:

    由于Get-WinEvent cmdlet 的-ComputerName 参数只接受字符串,您可能必须遍历列表:

    $StartDate = (get-date).AddHours(-12)
    
    Get-Content 'computers.txt' | ForEach-Object {
        Get-WinEvent -ComputerName $_ -FilterHashtable @{logname="System"; Level=1,2,3; starttime=$StartDate} -ErrorAction SilentlyContinue    
    }
    

    【讨论】:

    • 我试过你给的那个,但收到错误,Get-Winevent : The RPC server is unavailable。此外,它在本地机器上工作,但在computers.txt 上的其他机器上不起作用。
    • 这可能是另外一个话题了,随便搜索一下留言就知道了。
    • 尝试使用 IP 地址而不是计算机名称,它似乎工作正常。一旦完成进一步的测试,将更新此线程。谢谢,马丁!
    • 不客气。请考虑接受答案
    猜你喜欢
    • 1970-01-01
    • 2018-11-10
    • 1970-01-01
    • 1970-01-01
    • 2022-01-26
    • 1970-01-01
    • 1970-01-01
    • 2016-02-18
    • 1970-01-01
    相关资源
    最近更新 更多