【问题标题】:Powershell remote-query for Server 2003's eventlogServer 2003 事件日志的 Powershell 远程查询
【发布时间】:2014-02-06 22:59:54
【问题描述】:

有什么方法可以通过 Powershell 远程查询 2003 服务器上的事件。 Get-eventlog 没有 -credential 开关,get-winevent 在 Server 2003 上不起作用。

我什至尝试了impersonation module。它适用于get-serviceget-processget-counter 等命令,但不适用于get-wmiobjectget-eventlog。我是不是错过了什么。

【问题讨论】:

    标签: powershell powershell-2.0 windows-server-2003 event-log


    【解决方案1】:

    您可能正在寻找这个:

    Get-WmiObject Win32_NTLogEvent -ComputerName $compName -Credential $cred
    

    gmWin32_NTLogEventGet-WmiObject 结果(是的,可能需要一段时间才能生成):

    您可以用于过滤(即添加-filter "(TimeWritten>'$BeginDate')" 到gwmi 命令),不要忘记在此之前分配$BeginDate 变量。见这些:

    【讨论】:

    • 好的。这使我可以远程查看 2003 服务器的事件。但这使得将其缩小sourceEventIDbeforeafter 变得更加困难;不是吗。 TimeGenerated需要转换,找不到EventID叫什么。当我运行 Get-WmiObject Win32_NTLogEvent | gm 时 ISE 挂起
    • 没有简单的方法可以将-Credential 开关添加到Get-eventlog.....那真的很棒。
    • @AyanMullick:不,我认为你做不到。试试这个-filter "(TimeWritten>'$BeginDate')"this question/answer。您也可以选择only the fields you need - 可能会稍微快一些。我用更多信息更新了我的答案。
    • 我认为无法进一步回答已经回答的问题。 Get-WmiObject Win32_NTLogEvent 有效,但我认为 Get-WinEvent -Path 可能是更好的方法,因为它会使进一步的查询变得更加简单;如果只有.evt 文件没有被操作系统锁定。 :( 非常感谢您的帮助。
    • @AyanMullick:您需要使用 LIKE 运算符。
    【解决方案2】:

    将您的 Get-EventLog 命令包装在 Invoke-Command 脚本块中。

    【讨论】:

    • 我们无法在这些生产设备上启用 PsRemoting。 :(Connecting to remote server failed with the following error message : The client cannot connect to the destination specified in the request. Verify that the service on the destination is running and is accepting requests. Consult the logs and documentation for the WS-Management service running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to analyze and configure the WinRM service: "winrm quickconfig".
    • 如果您可以绕过 IT 部门实施的 PSRemoting 限制,那么您应该可以开始了。
    • 绝对@websch01ar;但获得环境 [12,000 台服务器] 的批准将是一项艰巨的任务。 :)
    • 好吧,我确实说祝你好运!哈哈。我在这里也有同样的论点,但我认为我们已经超越了这一点,因为工程师们开始欣赏......PowerShell的力量。
    猜你喜欢
    • 1970-01-01
    • 2012-11-22
    • 1970-01-01
    • 2014-10-22
    • 2013-05-23
    • 1970-01-01
    • 2023-02-20
    • 1970-01-01
    • 2011-05-19
    相关资源
    最近更新 更多